2 /* Prototype: bool is_int ( mixed $var );
3 * Description: Finds whether the given variable is an integer
6 echo "*** Testing is_int(), is_integer() & is_long() with valid integer values ***\n";
7 // different valid integer vlaues
12 -2147483648, // max negative integer value
14 2147483647, // max positive integer value
16 0x123B, // integer as hexadecimal
20 -0x80000000, // max negative integer as hexadecimal
21 0x7fffffff, // max postive integer as hexadecimal
22 0x7FFFFFFF, // max postive integer as hexadecimal
23 0123, // integer as octal
24 01912, // should be quivalent to octal 1
25 -020000000000, // max negative integer as octal
26 017777777777, // max positive integer as octal
28 /* loop to check that is_int() recognizes different
29 integer values, expected output: bool(true) */
31 foreach ($valid_ints as $int_val ) {
32 echo "--Iteration $loop_counter--\n"; $loop_counter++
;
33 var_dump( is_int($int_val) );
34 var_dump( is_integer($int_val) );
35 var_dump( is_long($int_val) );
38 echo "\n*** Testing is_int(), is_integer() & is_long() with non integer values ***\n";
40 // resource type variable
41 $fp = fopen (__FILE__
, "r");
42 $dfp = opendir ( dirname(__FILE__
) );
48 // other types in a array
49 $not_int_types = array (
51 -2147483649, // float value
52 2147483648, // float value
53 -0x80000001, // float value, beyond max negative int
54 0x800000001, // float value, beyond max positive int
55 020000000001, // float value, beyond max positive int
56 -020000000001, // float value, beyond max negative int
64 10.0000000000000000005,
86 array(1 => "One", "two" => 2),
114 /* undefined and unset vars */
118 /* loop through the $not_int_types to see working of
119 is_int() on non integer types, expected output: bool(false) */
121 foreach ($not_int_types as $type ) {
122 echo "--Iteration $loop_counter--\n"; $loop_counter++
;
123 var_dump( is_int($type) );
124 var_dump( is_integer($type) );
125 var_dump( is_long($type) );
128 echo "\n*** Testing error conditions ***\n";
130 var_dump( is_int() );
131 var_dump( is_integer() );
132 var_dump( is_long() );
134 //arguments more than expected
135 var_dump( is_int(TRUE, FALSE) );
136 var_dump( is_integer(TRUE, FALSE) );
137 var_dump( is_long(TRUE, FALSE) );
141 // close the resources