/**
  * 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 '?';
 }
Example #2
0
 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;
 }
/**
 * 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;
    }
}
Example #4
0
 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");
     }
 }
Example #5
0
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";
}
 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}.");
 }
Example #7
0
 /**
  * @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.");
     }
 }
Example #8
0
 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;
 }
Example #9
0
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";
}
Example #10
0
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);
    }
}
 /**
  * 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";
                     }
                 }
             }
         }
     }
 }
 /**
  * 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;
 }
Example #13
0
 public function IsNotReal()
 {
     $this->AddResult(!is_real($this->MethodOutput), 'Expected to be different from real (the number type!)');
 }
 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;
 }
Example #15
0
 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;
 }
 /**
  * @param mixed $variable
  * @param       $type
  *
  * @return bool
  */
 public static function is($variable, $type)
 {
     if (!in_array($type, [self::TYPE_ARRAY, self::TYPE_BOOLEAN, self::TYPE_CALLABLE, self::TYPE_DOUBLE, self::TYPE_FLOAT, self::TYPE_INT, self::TYPE_INTEGER, self::TYPE_LONG, self::TYPE_NULL, self::TYPE_NUMERIC, self::TYPE_OBJECT, self::TYPE_REAL, self::TYPE_RESOURCE, self::TYPE_SCALAR, self::TYPE_STRING])) {
         return false;
     }
     switch ($type) {
         case self::TYPE_ARRAY:
             return is_array($variable);
         case self::TYPE_BOOLEAN:
             return is_bool($variable);
         case self::TYPE_CALLABLE:
             return is_callable($variable);
         case self::TYPE_DOUBLE:
             return is_double($variable);
         case self::TYPE_FLOAT:
             return is_float($variable);
         case self::TYPE_INT:
             return is_int($variable);
         case self::TYPE_INTEGER:
             return is_integer($variable);
         case self::TYPE_LONG:
             return is_long($variable);
         case self::TYPE_NULL:
             return is_null($variable);
         case self::TYPE_NUMERIC:
             return is_numeric($variable);
         case self::TYPE_OBJECT:
             return is_object($variable);
         case self::TYPE_REAL:
             return is_real($variable);
         case self::TYPE_RESOURCE:
             return is_resource($variable);
         case self::TYPE_SCALAR:
             return is_scalar($variable);
         case self::TYPE_STRING:
             return is_string($variable);
         default:
             return false;
     }
 }
Example #17
0
 function export_data($fp, $name, $value)
 {
     global $ARCurrent;
     if (!is_null($value)) {
         fwrite($fp, "<var name=\"{$name}\">\n");
         if (is_bool($value)) {
             $value = $value ? 'true' : 'false';
             fwrite($fp, "<boolean>{$value}</boolean>\n");
         } else {
             if (is_int($value) || is_real($value) || is_float($value)) {
                 fwrite($fp, "<number>{$value}</number>\n");
             } else {
                 if (is_string($value) || $value === "") {
                     if ($ARCurrent->wddxoptions['srcpath'] != $ARCurrent->wddxoptions['dstpath']) {
                         $value = preg_replace('#(^|[\'"])' . $ARCurrent->wddxoptions['srcpath'] . '#i', '$1' . $ARCurrent->wddxoptions['dstpath'], $value);
                     }
                     fwrite($fp, "<string><![CDATA[" . export_wddx::strtoxmldata($value) . "]]></string>\n");
                 } else {
                     if (is_array($value) || is_object($value)) {
                         if (is_array($value)) {
                             fwrite($fp, "<struct type=\"hash\">\n");
                         } else {
                             fwrite($fp, "<struct type=\"object\" class=\"" . get_class($value) . "\">\n");
                         }
                         foreach ($value as $key => $val) {
                             export_wddx::export_data($fp, $key, $val);
                         }
                         fwrite($fp, "</struct>\n");
                     }
                 }
             }
         }
         fwrite($fp, "</var>\n");
     }
 }
Example #18
0
// unset variable
$unset_var = 10;
unset($unset_var);
// non_scalar values, objects, arrays, resources and boolean
class foo
{
    var $array = array(10.5);
}
$object = new foo();
$not_floats = array(new foo(), $object, $fp, $dfp, array(), array(NULL), array(5000000000.0), array(1, 2, 3, 4), array("string"), NULL, null, true, TRUE, false, FALSE, "", '', "0", '0', "0.0", '0.0', '0.5', "-0.5", "1e5", '1e5', '1.5e6_string', "1.5e6_string", 1, -1, 0, 12345, 0xff55, -0x673, 0123, -0123, @$unset_var, @$undefined_var);
/* loop through the $not_floats to see working of 
   is_float(), is_double() & is_real() on objects,
    arrays, boolean and others */
$loop_counter = 1;
foreach ($not_floats as $value) {
    echo "--Iteration {$loop_counter}--\n";
    $loop_counter++;
    var_dump(is_float($value));
    var_dump(is_double($value));
    var_dump(is_real($value));
}
echo "\n*** Testing error conditions ***\n";
//Zero argument
var_dump(is_float());
var_dump(is_double());
var_dump(is_real());
//arguments more than expected
var_dump(is_float($floats[0], $floats[1]));
var_dump(is_double($floats[0], $floats[1]));
var_dump(is_real($floats[0], $floats[1]));
echo "Done\n";
Example #19
0
function isReal($d)
{
    trueOrX(is_real($d), "not a real");
    return $d;
}
Example #20
0
 /**
  * _parseVariable() - Parse (recursively) a variable
  *
  * This method parse a variable, either returning informations about
  * this variable, or in the case of an object or array, returning
  * recursive informations about this variable.
  *
  * @param $variable A variable to explore
  */
 function _parseVariable($variable)
 {
     $lang = $this->lang;
     if (is_object($variable)) {
         return $this->_parseObject($variable);
     } elseif (is_array($variable)) {
         return $this->_parseArray($variable);
     } elseif (is_long($variable)) {
         $type = $this->messages['TYPE_LONG'][$lang];
     } elseif (is_int($variable)) {
         $type = $this->messages['TYPE_INT'][$lang];
     } elseif (is_integer($variable)) {
         $type = $this->messages['TYPE_INTEGER'][$lang];
     } elseif (is_double($variable)) {
         $type = $this->messages['TYPE_DOUBLE'][$lang];
     } elseif (is_float($variable)) {
         $type = $this->messages['TYPE_FLOAT'][$lang];
     } elseif (is_real($variable)) {
         $type = $this->messages['TYPE_REAL'][$lang];
     } elseif (is_string($variable)) {
         $type = $this->messages['TYPE_STRING'][$lang] . '[' . strlen($variable) . ']';
     } elseif (is_bool($variable)) {
         $type = $this->messages['TYPE_BOOLEAN'][$lang];
         if ($variable == true) {
             $variable = $this->messages['BOOLEAN_TRUE'][$lang];
         } else {
             $variable = $this->messages['BOOLEAN_FALSE'][$lang];
         }
     } elseif (is_numeric($variable)) {
         $type = $this->messages['TYPE_NUMERIC'][$lang];
     } elseif (is_resource($variable)) {
         $type = $this->messages['TYPE_RESOURCE'][$lang] . '[' . get_resource_type($variable) . ']';
     } elseif (is_scalar($variable)) {
         $type = $this->messages['TYPE_SCALAR'][$lang];
     } elseif (is_null($variable)) {
         $type = $this->messages['TYPE_NULL'][$lang];
         $variable = 'Null';
     } else {
         $type = $this->messages['TYPE_UNKNOWN'][$lang] . '[' . gettype($variable) . ']';
     }
     return array(VAR_DUMP_ARRAY_MAGIC => VAR_DUMP_MAGIC, VAR_DUMP_ARRAY_TYPE => $type, VAR_DUMP_ARRAY_VALUE => $variable);
 }
Example #21
0
VERIFY(!is_bool("test"));
VERIFY(is_int(123));
VERIFY(!is_int("123"));
VERIFY(is_integer(123));
VERIFY(!is_integer("123"));
VERIFY(is_long(123));
VERIFY(!is_long("123"));
VERIFY(is_double(123.4));
VERIFY(!is_double("123.4"));
VERIFY(is_float(123.4));
VERIFY(!is_float("123.4"));
VERIFY(is_numeric(123));
VERIFY(is_numeric("123.4"));
VERIFY(!is_numeric("e123.4"));
VERIFY(is_real(123.4));
VERIFY(!is_real("123.4"));
VERIFY(!is_string(123));
VERIFY(is_string("test"));
VERIFY(!is_scalar(null));
VERIFY(is_scalar(123));
VERIFY(is_scalar("test"));
VERIFY(!is_scalar(array(123)));
VERIFY(!is_scalar(new stdclass()));
VERIFY(!is_scalar($valid_res));
VERIFY(!is_scalar($invalid_res));
VERIFY(!is_array(null));
VERIFY(!is_array(123));
VERIFY(!is_array("test"));
VERIFY(is_array(array(123)));
VERIFY(!is_array(new stdclass()));
VERIFY(!is_array($valid_res));
Example #22
0
 private function getTypeInfo($value)
 {
     $type = null;
     $length = null;
     $default = null;
     if (is_bool($value)) {
         $type = 'BOOLEAN';
         $default = $value;
     }
     if (is_double($value)) {
         $type = 'DOUBLE';
     } else {
         if (is_float($value)) {
             $type = 'FLOAT';
         } else {
             if (is_real($value)) {
                 $type = 'REAL';
             } else {
                 if (is_numeric($value)) {
                     $type = 'INT';
                     $length = 11;
                 } else {
                     if (is_string($value)) {
                         $type = 'VARCHAR';
                         $length = 32;
                         while ($length < strlen($value)) {
                             $length *= 2;
                             if ($length > 2000) {
                                 $type = 'TEXT';
                                 break;
                             }
                         }
                         if ($type == 'VARCHAR') {
                             $length--;
                         } else {
                             while ($length < strlen($value)) {
                                 $length *= 2;
                                 if ($length > 10000) {
                                     $type = 'LONGTEXT';
                                     break;
                                 }
                             }
                             $length = null;
                         }
                     } else {
                         if (is_null($value)) {
                             // default case if get a NULL value
                             $type = 'INT';
                             $length = '11';
                         } else {
                             throw new MySQLCRUDException('unknown type for value: ' . gettype($value));
                         }
                     }
                 }
             }
         }
     }
     return ['type' => $type, 'length' => $length, 'default' => $default];
 }
Example #23
0
function packPolVar($PHPObject, $In_Array = FALSE)
{
    if (is_null($PHPObject)) {
        return array("Error" => "PHPObject passed to packPolVar() was NULL");
    }
    // We use the is_* Functions for this purpose because of the inaccuracy of the gettype() function.
    // Not only are the is_ functions more efficient from a processing point of view, but by using them at all
    // times to validate the data type of a variable, you get around the real possibility that a PHP Object
    // will have its type changed again somewhere else within the script. All much better OVERALL than a switch case.
    if (is_int($PHPObject)) {
        return 'i' . (string) $PHPObject . '';
    } else {
        if (is_float($PHPObject) || is_double($PHPObject) || is_real($PHPObject)) {
            (double) $PHPObject;
            // We force Cast to eliminate any issue on POL's end for handling the Numbers.
            return 'r' . (string) $PHPObject . '';
        } else {
            if (is_string($PHPObject)) {
                if ($In_Array === FALSE) {
                    return 's' . $PHPObject . '';
                } else {
                    return 'S' . (string) strlen($PHPObject) . ':' . $PHPObject . '';
                }
            } else {
                if (is_array($PHPObject)) {
                    // Check if it's empty. If it is, BOOOOO. Don't send EMPTY arrays. useless and buggy. Send a String instead.
                    if (count($PHPObject) < 1) {
                        return array("Error" => "Empty Array sent to packPolVar(). BAD DOG!");
                    }
                    // First check for Keys existing in the array. If they do, this needs to become a POL Struct!
                    // Never mix keyed and indexed arrays. Makes for messy code and results. We check the first result of
                    // array_keys to see if it is a string. If it is, there was Keys, and thus we need to make a POL Struct. At this stage, it
                    //  COULD be a Struct or Dictionary. But leaving it as a Struct only for the moment. This is mainly because I am lazy
                    // and do NOT want to check all results of they array_keys to see if this is a MIXED array of int and string keys.
                    $KeyCheck = array_keys($PHPObject);
                    if (is_string($KeyCheck[0])) {
                        return array("Error" => "Packing of STRUCT is not yet implemented");
                    } else {
                        if (is_int($KeyCheck[0])) {
                            // Time to begin packing. Will even handle multi-dimensional by passing them BACK to packPolVar()  for handling each entry.
                            return packPolArray($PHPObject);
                            //			return array ( "Error" => "Packing of Arrays is not yet implemented" );
                        }
                    }
                }
            }
        }
    }
}
Example #24
0
/**
 * bl_get_type()
 *
 * Because gettype() not is the way?
 *
 * @access private
 * @param mixed $var The var
 * @return string Type of var
 */
function bl_get_type($var)
{
    if (is_array($var)) {
        return 'Array';
    } elseif (is_object($var)) {
        return 'Object';
    } elseif (is_resource($var)) {
        return 'Resource';
    } elseif (is_bool($var)) {
        return 'Bool';
    } elseif (is_float($var)) {
        return 'Float';
    } elseif (is_double($var)) {
        return 'Double';
    } elseif (is_executable($var)) {
        return 'Executable';
    } elseif (is_int($var)) {
        return 'Int';
    } elseif (is_numeric($var)) {
        return 'Numeric';
    } elseif (is_real($var)) {
        return 'Real';
    } else {
        // para todo lo demas...
        return 'String';
    }
}
 /**
  * Bind values in prepared PDOStatement
  * 
  * @param PDOStatement $statement
  * @param array $values (make like this ==>> [ column1 => value1, column2 => value2, ..., columnN => valueN])
  * @return \PDOStatement PDOStatement with values bind to its coluns
  */
 private function bindValues(PDOStatement $statement, $values)
 {
     if (!is_null($values) || isset($values)) {
         foreach ($values as $key => $value) {
             if ($value === 'true' || $value === 'false') {
                 $value = $value === 'true';
             }
             $paramType = PDO::PARAM_STR;
             if (is_null($value) || $value === "null") {
                 $value = null;
                 $paramType = PDO::PARAM_NULL;
             } else {
                 if (is_integer($value)) {
                     $paramType = PDO::PARAM_INT;
                 } else {
                     if (is_real($value)) {
                         $paramType = PDO::PARAM_INT;
                     } else {
                         if (is_string($value)) {
                             $paramType = PDO::PARAM_STR;
                         } else {
                             if (is_bool($value)) {
                                 $paramType = PDO::PARAM_BOOL;
                             } else {
                                 $paramType = PDO::PARAM_LOB;
                             }
                         }
                     }
                 }
             }
             $statement->bindValue(":" . $key, $value, $paramType);
         }
     }
     return $statement;
 }
Example #26
0
//可以通过gettype()得到变量的类型
$var = 12;
$var = 12.3;
$var = '123king';
$var = true;
echo gettype($var);
echo '<hr color="red"/>';
//通过变量函数库检测变量的类型
$var = 12;
$var = 0;
$var = 2000.0;
var_dump(is_int($var), is_integer($var), is_long($var));
echo '<hr/>';
$var = 2.23;
$var = 200.0;
var_dump(is_float($var), is_double($var), is_real($var));
echo '<hr/>';
$var = '1';
$var = '';
var_dump(is_string($var));
echo '<hr/>';
$var = false;
var_dump(is_bool($var));
echo '<hr color="red"/>';
//检测是否为标量类型
$var = 0;
$var = null;
var_dump(is_scalar($var));
echo '<hr/>';
$var = null;
var_dump(is_null($varsdffsdfsddf));
Example #27
0
 /**
  * SECONDOFMINUTE
  *
  * @param	long	$timeValue		Excel time serial value or a standard time string
  * @return	int		Second
  */
 public static function SECONDOFMINUTE($timeValue = 0)
 {
     $timeValue = self::flattenSingleValue($timeValue);
     if (!is_numeric($timeValue)) {
         if (self::$compatibilityMode == self::COMPATIBILITY_GNUMERIC) {
             $testVal = strtok($timeValue, '/-: ');
             if (strlen($testVal) < strlen($timeValue)) {
                 return self::$_errorCodes['value'];
             }
         }
         $timeValue = self::_getTimeValue($timeValue);
         if (is_string($timeValue)) {
             return self::$_errorCodes['value'];
         }
     }
     // Execute function
     if (is_real($timeValue)) {
         if ($timeValue >= 1) {
             $timeValue = fmod($timeValue, 1);
         } elseif ($timeValue < 0.0) {
             return self::$_errorCodes['num'];
         }
         $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
     }
     return (int) date('s', $timeValue);
 }
 /**
  * Process XML with the annotated methods of the given class
  *
  * @param   xml.XPath XPath Instance of xml.XPath
  * @param   php.DomNode Context The XML node to recurse from
  * @param   string classname Fully qualified class name
  */
 public static function recurse($XPath, $Context, $classname)
 {
     if (DIA_UNM_DEBUG) {
         Console::writeLine('recurse: ' . $Context->tagname() . "-> {$classname}");
     }
     $Class = XPClass::forName($classname);
     $Instance = $Class->newInstance();
     if (DIA_UNM_DEBUG) {
         Console::writeLine('Instance: ' . $Instance->getClassName());
     }
     // loop over class methods with annotation 'fromDia'
     $methods = $Class->getMethods();
     foreach (array_keys($methods) as $key) {
         $Method = $methods[$key];
         if (!$Method->hasAnnotation('fromDia', 'xpath')) {
             continue;
         }
         $name = $Method->getName();
         $xpath = $Method->getAnnotation('fromDia', 'xpath');
         if (DIA_UNM_DEBUG) {
             Console::writeLine("--> Method: {$name} Xpath: {$xpath}");
         }
         // continue if this fails: some expressions don't work on WRONG nodes...
         try {
             $result = $XPath->query($xpath, $Context);
         } catch (Exception $e) {
             if (DIA_UNM_DEBUG) {
                 $e->printStackTrace();
             }
             $nodename = $Context->tagname();
             if ($Context->has_attribute('type')) {
                 $type = $Context->get_attribute('type');
             } else {
                 $type = '<unknown>';
             }
             if (DIA_UNM_DEBUG) {
                 Console::writeLine("Warn: XPath= '{$xpath}' failed on Node= '{$nodename}' Type= '{$type}'");
             }
             // skip this method/expression
             continue;
         }
         if (DIA_UNM_DEBUG) {
             Console::writeLine('  + Size of nodeset: ' . sizeof($result->nodeset));
         }
         // loop over nodeset
         foreach (array_keys($result->nodeset) as $key) {
             $Node = $result->nodeset[$key];
             // key 'value' (simple value)
             if ($Method->hasAnnotation('fromDia', 'value')) {
                 $type = $Method->getAnnotation('fromDia', 'value');
                 if (DIA_UNM_DEBUG) {
                     Console::writeLine("  + Value-type: '{$type}'");
                 }
                 // get node value depending on nod type
                 if (is('domattribute', $Node)) {
                     $nodevalue = $Node->value();
                 } elseif (is('domelement', $Node)) {
                     // remove whitespace and leading/trailing '#' character
                     $content = $Node->get_content();
                     if (isset($content) and $content !== '') {
                         $nodevalue = substr(trim($Node->get_content()), 1, -1);
                     } else {
                         $nodevalue = '';
                     }
                 } elseif (is('domnamespace', $Node)) {
                     $nodevalue = array($Node->prefix() => $Node->namespace_uri());
                 } else {
                     Console::writeLine('Unknown node class: ' . xp::stringOf($Node));
                     exit(-1);
                 }
                 switch ($type) {
                     case 'namespace':
                         if (!is_array($nodevalue) or empty($nodevalue)) {
                             Console::writeLine("Nodevalue is no array or is empty: {$nodevalue}");
                         }
                         $value = $nodevalue;
                         break;
                     case 'enum':
                     case 'int':
                         $nodevalue = cast($nodevalue, 'int');
                         if (!is_int($nodevalue)) {
                             Console::writeLine("Nodevalue is no integer: {$nodevalue}");
                         }
                         $value = $nodevalue;
                         break;
                     case 'real':
                         $nodevalue = cast($nodevalue, 'float');
                         if (!is_real($nodevalue) and !is_int($nodevalue)) {
                             Console::writeLine("Nodevalue is no float/integer: {$nodevalue}");
                         }
                         $value = $nodevalue;
                         break;
                     case 'string':
                         $nodevalue = cast($nodevalue, 'string');
                         if (!is_string($nodevalue)) {
                             Console::writeLine("Nodevalue is no string: {$nodevalue}");
                         }
                         $value = $nodevalue;
                         break;
                     case 'boolean':
                         $value = NULL;
                         if ($nodevalue === 'false') {
                             $value = FALSE;
                         }
                         if ($nodevalue === 'true') {
                             $value = TRUE;
                         }
                         if (!is_bool($value)) {
                             Console::writeLine("Nodevalue is no boolean: {$nodevalue}");
                         }
                         break;
                     case 'point':
                     case 'array':
                         // comma separated list of values
                         $value = explode(',', $nodevalue);
                         break;
                     case 'rectangle':
                     case 'arrayarray':
                         // semicolon and comma separated list of values
                         $points = explode(';', $nodevalue);
                         $value = array();
                         foreach ($points as $point) {
                             $value[] = explode(',', $point);
                         }
                         break;
                     case 'font':
                         if (is('domelement', $Node)) {
                             $value = array();
                             $value['family'] = $Node->get_attribute('family');
                             $value['style'] = $Node->get_attribute('style');
                             $value['name'] = $Node->get_attribute('name');
                         } else {
                             Console::writeLine('Wrong font node: ' . xp::stringOf($Node));
                             exit(-1);
                         }
                         break;
                     default:
                         Console::writeLine("!!!Unknown 'value' type: '{$type}'!");
                 }
                 $Method->invoke($Instance, array($value));
             }
             // key 'class'
             if ($Method->hasAnnotation('fromDia', 'class')) {
                 $classname = $Method->getAnnotation('fromDia', 'class');
                 if (DIA_UNM_DEBUG) {
                     Console::writeLine("  + Class: {$classname}");
                 }
                 // recurse with given classname
                 $Obj = DiaUnmarshaller::recurse($XPath, $Node, $classname);
                 // hand results over to the method
                 $Method->invoke($Instance, array($Obj));
             }
         }
     }
     return $Instance;
 }