1--TEST--
2Test is_int() & it's FALIASes: is_long() & is_integer() functions
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6?>
7--INI--
8precision=14
9--FILE--
10<?php
11/* Prototype: bool is_int ( mixed $var );
12 * Description: Finds whether the given variable is an integer
13 */
14
15echo "*** 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;
40foreach ($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
47echo "\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;
55unset ($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;
130foreach ($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
137echo "\n*** Testing error conditions ***\n";
138//Zero argument
139var_dump( is_int() );
140var_dump( is_integer() );
141var_dump( is_long() );
142
143//arguments more than expected
144var_dump( is_int(TRUE, FALSE) );
145var_dump( is_integer(TRUE, FALSE) );
146var_dump( is_long(TRUE, FALSE) );
147
148echo "Done\n";
149?>
150--EXPECTF--
151*** Testing is_int(), is_integer() & is_long()  with valid integer values ***
152--Iteration 1--
153bool(true)
154bool(true)
155bool(true)
156--Iteration 2--
157bool(true)
158bool(true)
159bool(true)
160--Iteration 3--
161bool(true)
162bool(true)
163bool(true)
164--Iteration 4--
165bool(true)
166bool(true)
167bool(true)
168--Iteration 5--
169bool(true)
170bool(true)
171bool(true)
172--Iteration 6--
173bool(true)
174bool(true)
175bool(true)
176--Iteration 7--
177bool(true)
178bool(true)
179bool(true)
180--Iteration 8--
181bool(true)
182bool(true)
183bool(true)
184--Iteration 9--
185bool(true)
186bool(true)
187bool(true)
188--Iteration 10--
189bool(true)
190bool(true)
191bool(true)
192--Iteration 11--
193bool(true)
194bool(true)
195bool(true)
196--Iteration 12--
197bool(true)
198bool(true)
199bool(true)
200--Iteration 13--
201bool(true)
202bool(true)
203bool(true)
204--Iteration 14--
205bool(true)
206bool(true)
207bool(true)
208--Iteration 15--
209bool(true)
210bool(true)
211bool(true)
212--Iteration 16--
213bool(true)
214bool(true)
215bool(true)
216--Iteration 17--
217bool(true)
218bool(true)
219bool(true)
220--Iteration 18--
221bool(true)
222bool(true)
223bool(true)
224
225*** Testing is_int(), is_integer() & is_long() with  non integer values ***
226--Iteration 1--
227bool(true)
228bool(true)
229bool(true)
230--Iteration 2--
231bool(true)
232bool(true)
233bool(true)
234--Iteration 3--
235bool(true)
236bool(true)
237bool(true)
238--Iteration 4--
239bool(true)
240bool(true)
241bool(true)
242--Iteration 5--
243bool(true)
244bool(true)
245bool(true)
246--Iteration 6--
247bool(true)
248bool(true)
249bool(true)
250--Iteration 7--
251bool(false)
252bool(false)
253bool(false)
254--Iteration 8--
255bool(false)
256bool(false)
257bool(false)
258--Iteration 9--
259bool(false)
260bool(false)
261bool(false)
262--Iteration 10--
263bool(false)
264bool(false)
265bool(false)
266--Iteration 11--
267bool(false)
268bool(false)
269bool(false)
270--Iteration 12--
271bool(false)
272bool(false)
273bool(false)
274--Iteration 13--
275bool(false)
276bool(false)
277bool(false)
278--Iteration 14--
279bool(false)
280bool(false)
281bool(false)
282--Iteration 15--
283bool(false)
284bool(false)
285bool(false)
286--Iteration 16--
287bool(false)
288bool(false)
289bool(false)
290--Iteration 17--
291bool(false)
292bool(false)
293bool(false)
294--Iteration 18--
295bool(false)
296bool(false)
297bool(false)
298--Iteration 19--
299bool(false)
300bool(false)
301bool(false)
302--Iteration 20--
303bool(false)
304bool(false)
305bool(false)
306--Iteration 21--
307bool(false)
308bool(false)
309bool(false)
310--Iteration 22--
311bool(false)
312bool(false)
313bool(false)
314--Iteration 23--
315bool(false)
316bool(false)
317bool(false)
318--Iteration 24--
319bool(false)
320bool(false)
321bool(false)
322--Iteration 25--
323bool(false)
324bool(false)
325bool(false)
326--Iteration 26--
327bool(false)
328bool(false)
329bool(false)
330--Iteration 27--
331bool(false)
332bool(false)
333bool(false)
334--Iteration 28--
335bool(false)
336bool(false)
337bool(false)
338--Iteration 29--
339bool(false)
340bool(false)
341bool(false)
342--Iteration 30--
343bool(false)
344bool(false)
345bool(false)
346--Iteration 31--
347bool(false)
348bool(false)
349bool(false)
350--Iteration 32--
351bool(false)
352bool(false)
353bool(false)
354--Iteration 33--
355bool(false)
356bool(false)
357bool(false)
358--Iteration 34--
359bool(false)
360bool(false)
361bool(false)
362--Iteration 35--
363bool(false)
364bool(false)
365bool(false)
366--Iteration 36--
367bool(false)
368bool(false)
369bool(false)
370--Iteration 37--
371bool(false)
372bool(false)
373bool(false)
374--Iteration 38--
375bool(false)
376bool(false)
377bool(false)
378--Iteration 39--
379bool(false)
380bool(false)
381bool(false)
382--Iteration 40--
383bool(false)
384bool(false)
385bool(false)
386--Iteration 41--
387bool(false)
388bool(false)
389bool(false)
390--Iteration 42--
391bool(false)
392bool(false)
393bool(false)
394--Iteration 43--
395bool(false)
396bool(false)
397bool(false)
398--Iteration 44--
399bool(false)
400bool(false)
401bool(false)
402--Iteration 45--
403bool(false)
404bool(false)
405bool(false)
406--Iteration 46--
407bool(false)
408bool(false)
409bool(false)
410--Iteration 47--
411bool(false)
412bool(false)
413bool(false)
414--Iteration 48--
415bool(false)
416bool(false)
417bool(false)
418--Iteration 49--
419bool(false)
420bool(false)
421bool(false)
422--Iteration 50--
423bool(false)
424bool(false)
425bool(false)
426--Iteration 51--
427bool(false)
428bool(false)
429bool(false)
430--Iteration 52--
431bool(false)
432bool(false)
433bool(false)
434--Iteration 53--
435bool(false)
436bool(false)
437bool(false)
438--Iteration 54--
439bool(false)
440bool(false)
441bool(false)
442
443*** Testing error conditions ***
444
445Warning: is_int() expects exactly 1 parameter, 0 given in %s on line %d
446bool(false)
447
448Warning: is_integer() expects exactly 1 parameter, 0 given in %s on line %d
449bool(false)
450
451Warning: is_long() expects exactly 1 parameter, 0 given in %s on line %d
452bool(false)
453
454Warning: is_int() expects exactly 1 parameter, 2 given in %s on line %d
455bool(false)
456
457Warning: is_integer() expects exactly 1 parameter, 2 given in %s on line %d
458bool(false)
459
460Warning: is_long() expects exactly 1 parameter, 2 given in %s on line %d
461bool(false)
462Done
463