本文整理汇总了PHP中is_real函数的典型用法代码示例。如果您正苦于以下问题:PHP is_real函数的具体用法?PHP is_real怎么用?PHP is_real使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_real函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValueInfo
/**
* return stacktrace-like information about the given variable
*
* @return string
*/
function getValueInfo($val)
{
if (is_null($val)) {
return 'null';
}
if (is_array($val)) {
return 'array[' . count($val) . ']';
}
if (is_bool($val)) {
return $val ? 'true' : 'false';
}
if (is_float($val) || is_int($val) || is_long($val) || is_real($val)) {
return 'num:' . $val;
}
if (is_string($val)) {
return 'string[' . strlen($val) . ']=' . substr($val, 0, 16);
}
if (is_resource($val)) {
return 'resource' . get_resource_type($val);
}
if (is_object($val)) {
return 'object';
}
return '?';
}
示例2: __construct
public function __construct($value = '', $cast = FALSE)
{
$isReal = is_real($value);
if (!$cast && !$isReal) {
throw new \Exception("Expected value must be of type float/double, " . gettype($value) . " given");
}
if ($cast && !$isReal) {
return $this->value = (double) $value;
}
$this->value = $value;
}
示例3: guessType
/**
* Guess the type of a variable.
*
* @ingroup config
* @param $value (mixed) the var
* @return (const type)
*/
function guessType($value)
{
if (is_bool($value)) {
return BOOL;
} elseif (is_real($value)) {
return REAL;
} elseif (is_int($value)) {
return NUMERIC;
} else {
return STRING;
}
}
示例4: checkValues
function checkValues($timestamp, $device, $latitude, $longitude, $message)
{
if (!is_integer($timestamp) || $timestamp <= 0) {
throw new Exception("Timestamp must be a a positive integer");
} elseif (!is_string($device) || !preg_match(AzimutDatabase::REGEX_DEVICE, $device)) {
throw new Exception("The field '" . AzimutDatabase::FIELD_DEVICE . "' must match " . AzimutDatabase::REGEX_DEVICE);
} elseif (!is_string($message) || !preg_match(AzimutDatabase::REGEX_MESSAGE, $message)) {
throw new Exception("The field '" . AzimutDatabase::FIELD_MESSAGE . "' must match " . AzimutDatabase::REGEX_MESSAGE);
} elseif (!is_real($latitude) || $latitude < -90 || $latitude > 90) {
throw new Exception("The field '" . AzimutDatabase::FIELD_LATITUDE . "' must be a float between -90 and 90");
} elseif (!is_real($longitude) || $longitude < -360 || $longitude > 360) {
throw new Exception("The field '" . AzimutDatabase::FIELD_LONGITUDE . "' must be a float between -360 and 360");
}
}
示例5: foo
function foo()
{
echo "set: " . isset($a) . "\n";
echo "nul: " . is_null($a) . "\n";
echo "str: " . is_string($a) . "\n";
echo "obj: " . is_object($a) . "\n";
echo "arr: " . is_array($a) . "\n";
echo "int: " . is_int($a) . "\n";
echo "integer: " . is_integer($a) . "\n";
echo "long: " . is_long($a) . "\n";
echo "real: " . is_real($a) . "\n";
echo "double: " . is_double($a) . "\n";
echo "float: " . is_float($a) . "\n";
echo "bool: " . is_bool($a) . "\n";
}
示例6: toPrimitiveType
public function toPrimitiveType($value)
{
if (is_null($value)) {
return null;
}
if (is_string($value)) {
$value = trim($value);
if (empty($value)) {
return null;
} else {
return $this->toNumeric($value);
}
}
if (is_integer($value) || is_long($value) || is_double($value) || is_float($value) || is_real($value) || is_numeric($value)) {
return $this->toNumeric($value);
}
throw new Exception("Invalid {$this->typeprefix}.");
}
示例7: generateHash
/**
* @internal
*
* Create hash for each element.
*
* @param $value
* @return string
*/
protected function generateHash($value)
{
if (is_object($value)) {
if ($value instanceof \Closure) {
throw new \InvalidArgumentException("Closure cannot be Dictionary key.");
}
return 'object:' . spl_object_hash($value);
} elseif (is_string($value)) {
return 'string:' . $value;
} elseif (is_int($value)) {
return 'int:' . $value;
} elseif (is_real($value)) {
return 'float:' . $value;
} elseif (is_bool($value)) {
return 'bool:' . (int) $value;
} elseif (is_null($value)) {
return 'null:null';
} else {
throw new \InvalidArgumentException("Invalid Dictionary key.");
}
}
示例8: checkType
private function checkType($obj, $escalate = true)
{
switch ($this->type) {
case 'string':
$valid = is_string($obj);
break;
case 'array':
$valid = is_array($obj);
break;
case 'bool':
case 'boolean':
$valid = is_bool($obj);
break;
case 'double':
$valid = is_double($obj);
break;
case 'real':
$valid = is_real($obj);
break;
case 'float':
$valid = is_float($obj);
break;
case 'int':
case 'integer':
$valid = is_int($obj);
break;
case 'object':
$valid = is_object($obj);
break;
default:
$valid = $obj instanceof $this->type;
break;
}
if (!$valid && $escalate) {
throw new InvalidArgumentException('Argument must be of type "' . $this->type . '".');
}
return $valid;
}
示例9: foo
function foo()
{
// Force all the types to be in so these don't get constant folded.
if (isset($GLOBALS['a'])) {
$a = 1;
}
if (isset($GLOBALS['b'])) {
$a = 1.2;
}
if (isset($GLOBALS['c'])) {
$a = '1';
}
if (isset($GLOBALS['d'])) {
$a = new stdclass();
}
if (isset($GLOBALS['e'])) {
$a = array();
}
if (isset($GLOBALS['f'])) {
$a = false;
}
if (isset($GLOBALS['g'])) {
$a = null;
}
echo "set: ", isset($a) . "\n";
echo "nul: ", is_null($a) . "\n";
echo "str: ", is_string($a) . "\n";
echo "obj: ", is_object($a) . "\n";
echo "arr: ", is_array($a) . "\n";
echo "int: ", is_int($a) . "\n";
echo "integer: ", is_integer($a) . "\n";
echo "long: ", is_long($a) . "\n";
echo "real: ", is_real($a) . "\n";
echo "double: ", is_double($a) . "\n";
echo "float: ", is_float($a) . "\n";
echo "bool: ", is_bool($a) . "\n";
}
示例10: check
function check($var)
{
if (is_array($var)) {
emitType($var);
} elseif (is_bool($var)) {
emitType($var);
} elseif (is_callable($var)) {
emitType($var);
} elseif (is_double($var)) {
emitType($var);
} elseif (is_float($var)) {
emitType($var);
} elseif (is_int($var)) {
emitType($var);
} elseif (is_integer($var)) {
emitType($var);
} elseif (is_bool($var)) {
emitType($var);
} elseif (is_long($var)) {
emitType($var);
} elseif (is_null($var)) {
emitType($var);
} elseif (is_numeric($var)) {
emitType($var);
} elseif (is_object($var)) {
emitType($var);
} elseif (is_real($var)) {
emitType($var);
} elseif (is_resource($var)) {
emitResourceType($var);
} elseif (is_scalar($var)) {
emitType($var);
} elseif (is_string($var)) {
emitType($var);
}
}
示例11: getMysqlTypeForValue
/**
* will determine a valid mysql column type from
* the input variable value
*/
protected function getMysqlTypeForValue($val)
{
if (preg_match('/\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}/', $val)) {
return "DATETIME";
} else {
if (is_string($val)) {
return "TEXT";
} else {
if (is_bool($val)) {
return "TINYINT";
} else {
if (is_int($val)) {
return "BIGINT";
} else {
if (is_double($val) || is_float($val) || is_real($val)) {
return "DOUBLE";
} else {
echo "unknown mysql type for: " . gettype($val) . "\n";
}
}
}
}
}
}
示例12: set_migration_column_attributes
/**
* Set the attributes of the migration
*
* @access private
* @param array $args Migration column attibutes
* @return void
* @author Aziz Light
**/
private function set_migration_column_attributes(array $args)
{
$extra = "\t\t\t'" . $args['column_name'] . '\' => array(' . PHP_EOL;
unset($args['column_name']);
foreach ($args as $attr => $value) {
$extra .= "\t\t\t\t'" . substr($attr, 7) . "' => ";
if (is_int($value) || is_real($value)) {
$extra .= $value;
} else {
if (is_bool($value)) {
$extra .= $value ? 'TRUE' : 'FALSE';
} else {
$extra .= "'" . $value . "'";
}
}
$extra .= ',' . PHP_EOL;
}
$extra .= "\t\t\t)," . PHP_EOL;
$this->extra = $extra;
return;
}
示例13: IsNotReal
public function IsNotReal()
{
$this->AddResult(!is_real($this->MethodOutput), 'Expected to be different from real (the number type!)');
}
示例14: devuelve_apostrofe
private function devuelve_apostrofe($variable)
{
$apostrofe = "";
switch (true) {
case is_bool($variable):
case is_double($variable):
case is_float($variable):
case is_int($variable):
case is_integer($variable):
case is_long($variable):
case is_numeric($variable):
case is_real($variable):
$apostrofe = "'";
break;
case is_string($variable):
$apostrofe = "'";
break;
default:
$apostrofe = '';
break;
}
return $apostrofe;
}
示例15: decimal
function decimal($field, $value)
{
if (is_numeric($value) || is_real($value)) {
$value = sprintf("%01.3f", $value);
}
$isValid = preg_match("/^([0-9]{1,5}[.]{1}[0-9]{1,5})\$/", $value);
if (!$isValid) {
$msg = "<span class=\"varname\">\"" . $this->field_label . "\"</span> A valid decimal value";
$this->error_list[] = array("field" => $field, "value" => $value, "msg" => $msg);
}
return $isValid;
}