/** * This function is the integeric partner of get_param, as it returns the value as an integer. * * @param ID_TEXT The name of the parameter to get * @param ?mixed The default value to give the parameter if the parameter value is not defined (NULL: give error on missing parameter) * @return integer The parameter value */ function get_param_integer($name, $default = NULL) { $ret = __param($_GET, $name, $default === false ? false : (is_null($default) ? NULL : strval($default))); if (is_null($default) && ($ret === '' || is_null($ret))) { return NULL; } return intval($ret); }
/** * This function is the integeric partner of get_param, as it returns the value as an integer. * * @param ID_TEXT The name of the parameter to get * @param ?mixed The default value to give the parameter if the parameter value is not defined or the empty string (NULL: allow missing parameter) (false: give error on missing parameter) * @param boolean If a string is given, use the default parameter rather than giving an error (only use this if you are suffering from a parameter conflict situation between different parts of ocPortal) * @return ?integer The parameter value (NULL: not set, and NULL given as default) */ function get_param_integer($name, $default = false, $not_string_ok = false) { $m_default = $default === false ? false : (isset($default) ? $default == 0 ? '0' : strval($default) : ''); $ret = __param($_GET, $name, $m_default, true); // do not set $ret to mixed(), breaks bootstrapping if (!isset($default) && $ret === '') { return NULL; } $ret = trim($ret); if (!is_numeric($ret)) { if (substr($ret, -1) == '/') { $ret = substr($ret, 0, strlen($ret) - 1); } if (!is_numeric($ret)) { $matches = array(); if (preg_match('#^(\\d+)\\#[\\w]*$#', $ret, $matches) != 0) { $ret = $matches[1]; } else { if ($not_string_ok) { return $default; } require_code('failure'); $ret = _param_invalid($name, $ret, false); } } } if ($ret == '0') { return 0; } if ($ret == '1') { return 1; } $reti = intval($ret); $retf = floatval($reti); if ($retf > 2147483647.0 || $retf < -2147483648.0) { require_code('failure'); _param_invalid($name, NULL, false); } return $reti; }
function postParam($name, $default = null) { return __param($_POST, $name, $default); }