]> granicus.if.org Git - php/blob
8e5e9332c0
[php] /
1 --TEST--
2 Test is_int() & it's FALIASes: is_long() & is_integer() functions
3 --SKIPIF--
4 <?php
5 if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6 ?>
7 --INI--
8 precision=14
9 --FILE--
10 <?php
11 /* Prototype: bool is_int ( mixed $var );
12  * Description: Finds whether the given variable is an integer
13  */
14
15 echo "*** Testing is_int(), is_integer() & is_long()  with valid integer values ***\n";
16 // different valid  integer values
17 $valid_ints = array(
18   0,
19   1,
20   -1,
21   -2147483648, // max negative integer value
22   -2147483647,
23   2147483647,  // max positive integer value
24   2147483640,
25   0x123B,      // integer as hexadecimal
26   0x12ab,
27   0Xfff,
28   0XFA,
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
36 );
37 /* loop to check that is_int() recognizes different
38    integer values, expected output: bool(true) */
39 $loop_counter = 1;
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) );
45 }
46
47 echo "\n*** Testing is_int(), is_integer() & is_long() with  non integer values ***\n";
48
49 // resource type variable
50 $fp = fopen (__FILE__, "r");
51 $dfp = opendir ( __DIR__ );
52 // unset variable
53
54 $unset_var = 10;
55 unset ($unset_var);
56
57 // other types in a array
58 $not_int_types = array (
59   /* float values */
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
66   0.0,
67   -0.1,
68   1.0,
69   1e5,
70   -1e6,
71   1E8,
72   -1E9,
73   10.0000000000000000005,
74   10.5e+5,
75
76   /* objects */
77   new stdclass,
78
79   /* resources */
80   $fp,
81   $dfp,
82
83   /* arrays */
84   array(),
85   array(0),
86   array(1),
87   array(NULL),
88   array(null),
89   array("string"),
90   array(true),
91   array(TRUE),
92   array(false),
93   array(FALSE),
94   array(1,2,3,4),
95   array(1 => "One", "two" => 2),
96
97   /* strings */
98   "",
99   '',
100   "0",
101   '0',
102   "1",
103   '1',
104   "\x01",
105   '\x01',
106   "\01",
107   '\01',
108   'string',
109   "string",
110   "true",
111   "FALSE",
112   'false',
113   'TRUE',
114   "NULL",
115   'null',
116
117   /* booleans */
118   true,
119   false,
120   TRUE,
121   FALSE,
122
123   /* undefined and unset vars */
124   @$unset_var,
125   @$undefined_var
126 );
127 /* loop through the $not_int_types to see working of
128    is_int() on non integer types, expected output: bool(false) */
129 $loop_counter = 1;
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) );
135 }
136
137 echo "Done\n";
138 ?>
139 --EXPECT--
140 *** Testing is_int(), is_integer() & is_long()  with valid integer values ***
141 --Iteration 1--
142 bool(true)
143 bool(true)
144 bool(true)
145 --Iteration 2--
146 bool(true)
147 bool(true)
148 bool(true)
149 --Iteration 3--
150 bool(true)
151 bool(true)
152 bool(true)
153 --Iteration 4--
154 bool(true)
155 bool(true)
156 bool(true)
157 --Iteration 5--
158 bool(true)
159 bool(true)
160 bool(true)
161 --Iteration 6--
162 bool(true)
163 bool(true)
164 bool(true)
165 --Iteration 7--
166 bool(true)
167 bool(true)
168 bool(true)
169 --Iteration 8--
170 bool(true)
171 bool(true)
172 bool(true)
173 --Iteration 9--
174 bool(true)
175 bool(true)
176 bool(true)
177 --Iteration 10--
178 bool(true)
179 bool(true)
180 bool(true)
181 --Iteration 11--
182 bool(true)
183 bool(true)
184 bool(true)
185 --Iteration 12--
186 bool(true)
187 bool(true)
188 bool(true)
189 --Iteration 13--
190 bool(true)
191 bool(true)
192 bool(true)
193 --Iteration 14--
194 bool(true)
195 bool(true)
196 bool(true)
197 --Iteration 15--
198 bool(true)
199 bool(true)
200 bool(true)
201 --Iteration 16--
202 bool(true)
203 bool(true)
204 bool(true)
205 --Iteration 17--
206 bool(true)
207 bool(true)
208 bool(true)
209 --Iteration 18--
210 bool(true)
211 bool(true)
212 bool(true)
213
214 *** Testing is_int(), is_integer() & is_long() with  non integer values ***
215 --Iteration 1--
216 bool(true)
217 bool(true)
218 bool(true)
219 --Iteration 2--
220 bool(true)
221 bool(true)
222 bool(true)
223 --Iteration 3--
224 bool(true)
225 bool(true)
226 bool(true)
227 --Iteration 4--
228 bool(true)
229 bool(true)
230 bool(true)
231 --Iteration 5--
232 bool(true)
233 bool(true)
234 bool(true)
235 --Iteration 6--
236 bool(true)
237 bool(true)
238 bool(true)
239 --Iteration 7--
240 bool(false)
241 bool(false)
242 bool(false)
243 --Iteration 8--
244 bool(false)
245 bool(false)
246 bool(false)
247 --Iteration 9--
248 bool(false)
249 bool(false)
250 bool(false)
251 --Iteration 10--
252 bool(false)
253 bool(false)
254 bool(false)
255 --Iteration 11--
256 bool(false)
257 bool(false)
258 bool(false)
259 --Iteration 12--
260 bool(false)
261 bool(false)
262 bool(false)
263 --Iteration 13--
264 bool(false)
265 bool(false)
266 bool(false)
267 --Iteration 14--
268 bool(false)
269 bool(false)
270 bool(false)
271 --Iteration 15--
272 bool(false)
273 bool(false)
274 bool(false)
275 --Iteration 16--
276 bool(false)
277 bool(false)
278 bool(false)
279 --Iteration 17--
280 bool(false)
281 bool(false)
282 bool(false)
283 --Iteration 18--
284 bool(false)
285 bool(false)
286 bool(false)
287 --Iteration 19--
288 bool(false)
289 bool(false)
290 bool(false)
291 --Iteration 20--
292 bool(false)
293 bool(false)
294 bool(false)
295 --Iteration 21--
296 bool(false)
297 bool(false)
298 bool(false)
299 --Iteration 22--
300 bool(false)
301 bool(false)
302 bool(false)
303 --Iteration 23--
304 bool(false)
305 bool(false)
306 bool(false)
307 --Iteration 24--
308 bool(false)
309 bool(false)
310 bool(false)
311 --Iteration 25--
312 bool(false)
313 bool(false)
314 bool(false)
315 --Iteration 26--
316 bool(false)
317 bool(false)
318 bool(false)
319 --Iteration 27--
320 bool(false)
321 bool(false)
322 bool(false)
323 --Iteration 28--
324 bool(false)
325 bool(false)
326 bool(false)
327 --Iteration 29--
328 bool(false)
329 bool(false)
330 bool(false)
331 --Iteration 30--
332 bool(false)
333 bool(false)
334 bool(false)
335 --Iteration 31--
336 bool(false)
337 bool(false)
338 bool(false)
339 --Iteration 32--
340 bool(false)
341 bool(false)
342 bool(false)
343 --Iteration 33--
344 bool(false)
345 bool(false)
346 bool(false)
347 --Iteration 34--
348 bool(false)
349 bool(false)
350 bool(false)
351 --Iteration 35--
352 bool(false)
353 bool(false)
354 bool(false)
355 --Iteration 36--
356 bool(false)
357 bool(false)
358 bool(false)
359 --Iteration 37--
360 bool(false)
361 bool(false)
362 bool(false)
363 --Iteration 38--
364 bool(false)
365 bool(false)
366 bool(false)
367 --Iteration 39--
368 bool(false)
369 bool(false)
370 bool(false)
371 --Iteration 40--
372 bool(false)
373 bool(false)
374 bool(false)
375 --Iteration 41--
376 bool(false)
377 bool(false)
378 bool(false)
379 --Iteration 42--
380 bool(false)
381 bool(false)
382 bool(false)
383 --Iteration 43--
384 bool(false)
385 bool(false)
386 bool(false)
387 --Iteration 44--
388 bool(false)
389 bool(false)
390 bool(false)
391 --Iteration 45--
392 bool(false)
393 bool(false)
394 bool(false)
395 --Iteration 46--
396 bool(false)
397 bool(false)
398 bool(false)
399 --Iteration 47--
400 bool(false)
401 bool(false)
402 bool(false)
403 --Iteration 48--
404 bool(false)
405 bool(false)
406 bool(false)
407 --Iteration 49--
408 bool(false)
409 bool(false)
410 bool(false)
411 --Iteration 50--
412 bool(false)
413 bool(false)
414 bool(false)
415 --Iteration 51--
416 bool(false)
417 bool(false)
418 bool(false)
419 --Iteration 52--
420 bool(false)
421 bool(false)
422 bool(false)
423 --Iteration 53--
424 bool(false)
425 bool(false)
426 bool(false)
427 --Iteration 54--
428 bool(false)
429 bool(false)
430 bool(false)
431 Done