2 Test is_int() & it's FALIASes: is_long() & is_integer() functions
5 if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
11 /* Prototype: bool is_int ( mixed $var );
12 * Description: Finds whether the given variable is an integer
15 echo "*** Testing is_int(), is_integer() & is_long() with valid integer values ***\n";
16 // different valid integer values
21 -2147483648, // max negative integer value
23 2147483647, // max positive integer value
25 0x123B, // integer as hexadecimal
29 -0x80000000, // max negative integer as hexadecimal
30 0x7fffffff, // max positive integer as hexadecimal
31 0x7FFFFFFF, // max positive integer as hexadecimal
32 0123, // integer as octal
33 01, // should be quivalent to octal 1
34 -020000000000, // max negative integer as octal
35 017777777777, // max positive integer as octal
37 /* loop to check that is_int() recognizes different
38 integer values, expected output: bool(true) */
40 foreach ($valid_ints as $int_val ) {
41 echo "--Iteration $loop_counter--\n"; $loop_counter++;
42 var_dump( is_int($int_val) );
43 var_dump( is_integer($int_val) );
44 var_dump( is_long($int_val) );
47 echo "\n*** Testing is_int(), is_integer() & is_long() with non integer values ***\n";
49 // resource type variable
50 $fp = fopen (__FILE__, "r");
51 $dfp = opendir ( __DIR__ );
57 // other types in a array
58 $not_int_types = array (
60 -2147483649, // float value
61 2147483648, // float value
62 -0x80000001, // float value, beyond max negative int
63 0x800000001, // float value, beyond max positive int
64 020000000001, // float value, beyond max positive int
65 -020000000001, // float value, beyond max negative int
73 10.0000000000000000005,
95 array(1 => "One", "two" => 2),
123 /* undefined and unset vars */
127 /* loop through the $not_int_types to see working of
128 is_int() on non integer types, expected output: bool(false) */
130 foreach ($not_int_types as $type ) {
131 echo "--Iteration $loop_counter--\n"; $loop_counter++;
132 var_dump( is_int($type) );
133 var_dump( is_integer($type) );
134 var_dump( is_long($type) );
140 *** Testing is_int(), is_integer() & is_long() with valid integer values ***
214 *** Testing is_int(), is_integer() & is_long() with non integer values ***