1--TEST--
2Test is_null() function
3--FILE--
4<?php
5/* Prototype: bool is_null ( mixed $var );
6 * Description: Finds whether the given variable is NULL
7 */
8
9echo "*** Testing is_null() with valid null values ***\n";
10// different valid  null values
11$unset_array = array();
12$unset_int = 10;
13$unset_float = 10.5;
14$unset_bool = true;
15$unset_object = new stdclass;
16$unset_resource = fopen(__FILE__, "r");
17// unset them to make it null.
18unset ($unset_array, $unset_int, $unset_float, $unset_bool, $unset_object, $unset_resource);
19$null_var1 = NULL;
20$null_var2 = null;
21
22$valid_nulls = array(
23  NULL,
24  null,
25  @$null_var1,
26  @$null_var2,
27  @$unset_array,
28  @$unset_int,
29  @$unset_float,
30  @$unset_bool,
31  @$unset_object,
32  @$unset_resource,
33  @$undefined_var,
34);
35/* loop to check that is_null() recognizes different
36   null values, expected output: bool(true) */
37$loop_counter = 1;
38foreach ($valid_nulls as $null_val ) {
39  echo "-- Iteration $loop_counter --\n"; $loop_counter++;
40  var_dump( is_null($null_val) );
41}
42
43echo "\n*** Testing is_bool() on non null values ***\n";
44
45// get a resource type variable
46$fp = fopen (__FILE__, "r");
47$dfp = opendir ( __DIR__ );
48
49// other types in a array
50$not_null_types = array (
51/* integers */
52  0,
53  1,
54  -1,
55  -0,
56  543915,
57  -5322,
58  0x0,
59  0x1,
60  0x55F,
61  -0xCCF,
62  0123,
63  -0654,
64  00,
65  01,
66
67  /* strings */
68  "",
69  '',
70  "0",
71  '0',
72  "1",
73  '1',
74  'string',
75  "string",
76  "true",
77  "false",
78  "FALSE",
79  "TRUE",
80  'true',
81  'false',
82  'FALSE',
83  'TRUE',
84  "NULL",
85  "null",
86
87  /* floats */
88  0.0,
89  1.0,
90  -1.0,
91  10.0000000000000000005,
92  .5e6,
93  -.5E7,
94  .5E+8,
95  -.5e+90,
96  1e5,
97  -1e5,
98  1E5,
99  -1E7,
100
101  /* objects */
102  new stdclass,
103
104  /* resources */
105  $fp,
106  $dfp,
107
108  /* arrays */
109  array(),
110  array(0),
111  array(1),
112  array(NULL),
113  array(null),
114  array("string"),
115  array(true),
116  array(TRUE),
117  array(false),
118  array(FALSE),
119  array(1,2,3,4),
120  array(1 => "One", "two" => 2),
121);
122/* loop through the $not_null_types to see working of
123   is_null() on non null types, expected output: bool(false) */
124$loop_counter = 1;
125foreach ($not_null_types as $type ) {
126  echo "-- Iteration $loop_counter --\n"; $loop_counter++;
127  var_dump( is_null($type) );
128}
129
130echo "\n*** Testing error conditions ***\n";
131//Zero argument
132var_dump( is_null() );
133
134//arguments more than expected
135var_dump( is_null(NULL, null) );
136
137echo "Done\n";
138
139// close the resources used
140fclose($fp);
141closedir($dfp);
142
143?>
144--EXPECTF--
145*** Testing is_null() with valid null values ***
146-- Iteration 1 --
147bool(true)
148-- Iteration 2 --
149bool(true)
150-- Iteration 3 --
151bool(true)
152-- Iteration 4 --
153bool(true)
154-- Iteration 5 --
155bool(true)
156-- Iteration 6 --
157bool(true)
158-- Iteration 7 --
159bool(true)
160-- Iteration 8 --
161bool(true)
162-- Iteration 9 --
163bool(true)
164-- Iteration 10 --
165bool(true)
166-- Iteration 11 --
167bool(true)
168
169*** Testing is_bool() on non null values ***
170-- Iteration 1 --
171bool(false)
172-- Iteration 2 --
173bool(false)
174-- Iteration 3 --
175bool(false)
176-- Iteration 4 --
177bool(false)
178-- Iteration 5 --
179bool(false)
180-- Iteration 6 --
181bool(false)
182-- Iteration 7 --
183bool(false)
184-- Iteration 8 --
185bool(false)
186-- Iteration 9 --
187bool(false)
188-- Iteration 10 --
189bool(false)
190-- Iteration 11 --
191bool(false)
192-- Iteration 12 --
193bool(false)
194-- Iteration 13 --
195bool(false)
196-- Iteration 14 --
197bool(false)
198-- Iteration 15 --
199bool(false)
200-- Iteration 16 --
201bool(false)
202-- Iteration 17 --
203bool(false)
204-- Iteration 18 --
205bool(false)
206-- Iteration 19 --
207bool(false)
208-- Iteration 20 --
209bool(false)
210-- Iteration 21 --
211bool(false)
212-- Iteration 22 --
213bool(false)
214-- Iteration 23 --
215bool(false)
216-- Iteration 24 --
217bool(false)
218-- Iteration 25 --
219bool(false)
220-- Iteration 26 --
221bool(false)
222-- Iteration 27 --
223bool(false)
224-- Iteration 28 --
225bool(false)
226-- Iteration 29 --
227bool(false)
228-- Iteration 30 --
229bool(false)
230-- Iteration 31 --
231bool(false)
232-- Iteration 32 --
233bool(false)
234-- Iteration 33 --
235bool(false)
236-- Iteration 34 --
237bool(false)
238-- Iteration 35 --
239bool(false)
240-- Iteration 36 --
241bool(false)
242-- Iteration 37 --
243bool(false)
244-- Iteration 38 --
245bool(false)
246-- Iteration 39 --
247bool(false)
248-- Iteration 40 --
249bool(false)
250-- Iteration 41 --
251bool(false)
252-- Iteration 42 --
253bool(false)
254-- Iteration 43 --
255bool(false)
256-- Iteration 44 --
257bool(false)
258-- Iteration 45 --
259bool(false)
260-- Iteration 46 --
261bool(false)
262-- Iteration 47 --
263bool(false)
264-- Iteration 48 --
265bool(false)
266-- Iteration 49 --
267bool(false)
268-- Iteration 50 --
269bool(false)
270-- Iteration 51 --
271bool(false)
272-- Iteration 52 --
273bool(false)
274-- Iteration 53 --
275bool(false)
276-- Iteration 54 --
277bool(false)
278-- Iteration 55 --
279bool(false)
280-- Iteration 56 --
281bool(false)
282-- Iteration 57 --
283bool(false)
284-- Iteration 58 --
285bool(false)
286-- Iteration 59 --
287bool(false)
288
289*** Testing error conditions ***
290
291Warning: is_null() expects exactly 1 parameter, 0 given in %s on line %d
292bool(false)
293
294Warning: is_null() expects exactly 1 parameter, 2 given in %s on line %d
295bool(false)
296Done
297