2 Test is_scalar() function
5 /* Prototype: bool is_scalar ( mixed $var );
6 * Description: Finds whether a variable is a scalar (i.e integer, float, string or boolean)
9 echo "*** Testing basic operations ***\n";
10 $scalar_variables = array(
14 0x5FF, // hexadecimal as integer
18 01234, // octal as integer
37 "0", // numeric as string
48 /* loop through each valid scalar variables in $scalar_variables
49 and see the working of is_scalar(), expected output: bool(true)
52 foreach($scalar_variables as $scalar) {
53 echo "-- Iteration $loop_counter --\n"; $loop_counter++;
54 var_dump( is_scalar($scalar) );
57 echo "\n*** Testing possible variations ***\n";
58 // different scalar variables which are unset
61 $string_var = "string";
63 $object = new stdclass;
65 $resource = opendir('.');
66 unset($int_var, $float_var, $string_var, $boolean_var, $object, $array, $resource);
69 $fp = fopen(__FILE__, "r");
72 $variation_array = array(
85 new stdclass, // object
87 @$int_var, // scalars that are unset
92 @$array, // non scalars that are unset
96 @$undefined_var // undefined variable
99 /* loop through each element of $variation_array to see the
100 working of is_scalar on non-scalar values, expected output: bool(false)
103 foreach( $variation_array as $value ) {
104 echo "-- Iteration $loop_counter --\n"; $loop_counter++;
105 var_dump( is_scalar($value) );
110 // close the resources used
116 *** Testing basic operations ***
184 *** Testing possible variations ***