protected function getRequestArgument($argumentName, $default, $dataType = "string") { if (array_key_exists($argumentName, $this->arguments)) { $argumentValue = $this->arguments[$argumentName]; if (setType($argumentValue, $dataType)) { return $argumentValue; } } return $default; }
/** * Modify properties of a certain user * * # DON'T MODIFY THE PASSWORD WITH THIS METHOD! * * You should use this method only if the 'name map' is used, too. * * Returns a PEAR_Error if: * o user doesn't exist * o any property contains a colon (':') * * @see changePasswd() * * @throws PEAR_Error * @access public * @return mixed true on success or PEAR_Error * @param string $user the user to modify * @param array $properties an associative array of * properties to modify */ function modUser($user, $properties = array()) { if (!$this->userExists($user)) { return PEAR::raiseError(sprintf(FILE_PASSWD_E_EXISTS_NOT_STR, 'User ', $user), FILE_PASSWD_E_EXISTS_NOT); } if (!is_array($properties)) { setType($properties, 'array'); } foreach ($properties as $key => $value) { if (strstr($value, ':')) { return PEAR::raiseError(sprintf(FILE_PASSWD_E_INVALID_CHARS_STR, 'User ', $user), FILE_PASSWD_E_INVALID_CHARS); } $this->_users[$user][$key] = $value; } return true; }
/** * Add an user * * The username must start with an alphabetical character and must NOT * contain any other characters than alphanumerics, the underline and dash. * * Returns a PEAR_Error if: * o user already exists * o user or system_user contains illegal characters * * @throws PEAR_Error * @access public * @return mixed true on success or PEAR_Error * @param string $user the name of the user to add * @param string $pass the password of the user tot add * @param string $system_user the systemuser this user maps to */ function addUser($user, $pass, $system_user = '') { if ($this->userExists($user)) { return PEAR::raiseError(sprintf(FILE_PASSWD_E_EXISTS_ALREADY_STR, 'User ', $user), FILE_PASSWD_E_EXISTS_ALREADY); } if (!preg_match($this->_pcre, $user)) { return PEAR::raiseError(sprintf(FILE_PASSWD_E_INVALID_CHARS_STR, 'User ', $user), FILE_PASSWD_E_INVALID_CHARS); } @setType($system_user, 'string'); if (!empty($system_user) && !preg_match($this->_pcre, $system_user)) { return PEAR::raiseError(sprintf(FILE_PASSWD_E_INVALID_CHARS_STR, 'System user ', $system_user), FILE_PASSWD_E_INVALID_CHARS); } $this->_users[$user]['passwd'] = $this->generatePassword($pass); $this->_users[$user]['system'] = $system_user; return true; }
case '7': $m = memory_get_usage(); $s = microtime(1); for ($i = 0; $i < $loops; $i++) { $v = array('a', 'b', 'c'); $v = (object) $v; } $return = array('$v = (object)array', microtime(1) - $s, memory_get_usage() - $m); echo serialize($return); break; case '8': $m = memory_get_usage(); $s = microtime(1); for ($i = 0; $i < $loops; $i++) { $v = (object) array('a', 'b', 'c'); setType($v, 'array'); } $return = array('setType(object, "array")', microtime(1) - $s, memory_get_usage() - $m); echo serialize($return); break; case '9': $m = memory_get_usage(); $s = microtime(1); for ($i = 0; $i < $loops; $i++) { $v = (object) array('a', 'b', 'c'); $v = (array) $v; } $return = array('$v = (array)object', microtime(1) - $s, memory_get_usage() - $m); echo serialize($return); break; }
static function floatOrNull($in) { if (is_null($in)) { return null; } if (!is_numeric($in)) { throw new caster_StrictTypeException('Expected Float or Null, received: ' . $in . ' (' . gettype($in) . ')'); } setType($in, 'float'); return $in; }
/** * Creates a number field for the form... basically a text field * * @access public * @param array fields parameters * @return string */ public function create_number($params) { $defaults = array('min' => '0', 'max' => NULL, 'step' => NULL, 'decimal' => 0, 'negative' => 0); $params = $this->normalize_params($params, $defaults); $attrs = array('id' => $params['id'], 'class' => $params['class'], 'readonly' => $params['readonly'], 'disabled' => $params['disabled'], 'required' => !empty($params['required']) ? TRUE : NULL, 'min' => isset($params['min']) ? $params['min'] : '0', 'max' => isset($params['max']) ? $params['max'] : '10000', 'step' => isset($params['step']) ? $params['step'] : NULL, 'data' => $params['data'], 'style' => $params['style'], 'tabindex' => $params['tabindex'], 'attributes' => $params['attributes']); // force to a string so that it doesn't go to negative number if the value is set to 0 setType($attrs['min'], 'string'); $numeric_class = 'numeric'; $attrs['class'] = !empty($params['class']) ? $params['class'] . ' ' . $numeric_class : $numeric_class; $params['type'] = 'number'; $decimal = !empty($params['decimal']) ? (int) $params['decimal'] : 0; $negative = !empty($params['negative']) ? 1 : 0; // invalid HTML // if (empty($params['size'])) // { // $attrs['size'] = 10; // } // if (empty($params['maxlength'])) // { // $attrs['maxlength'] = 10; // } // set data values for jquery plugin to use $attrs['data'] = array('decimal' => $decimal, 'negative' => $negative); return $this->form->input($params['name'], $params['type'], $params['value'], $attrs); }
function deleteIVRDB($idIVR) { if ($this->validateIvrPBX() == false) { return false; } setType($idIVR, "integer"); $queryDeleteIVRDestine = "delete from ivr_destination where ivr_id=?"; $result = $this->_DB->genQuery($queryDeleteIVRDestine, array($idIVR)); if ($result == false) { $this->errMsg = _tr("Error deleting IVR destinies. ") . $this->_DB->errMsg; return false; } $queryDeleteIVR = "delete from ivr where id=? and organization_domain=?"; $result = $this->_DB->genQuery($queryDeleteIVR, array($idIVR, $this->domain)); if ($result == false) { $this->errMsg = _tr("Error deleting IVR. ") . $this->_DB->errMsg; } return $result; }
$str1 = "str"; echo "<hr />str1:"; echo isset($str1); echo "<hr />"; var_dump((int) true, (int) false); $res = "4.444hello" + 1; echo "<hr />"; var_dump($res); $res2 = "4.0hello" + 1; echo "<hr />"; var_dump($res2); $res3 = "4.0e2hello" + 1; var_dump($res3); echo "<hr />"; var_dump((bool) 0); echo "<hr />"; var_dump((bool) 0); echo "<hr />"; var_dump((bool) 0); echo "<hr />"; var_dump((bool) "0."); echo "<hr />"; var_dump((bool) "0"); echo "<hr />11"; $foo = "5hello"; var_dump(setType($foo, 'int')); $arr = array(); echo "<hr /> arr:"; var_dump((bool) $arr); echo "<br />"; var_dump(empty($arr));