1--TEST--
2Test gettype() & settype() functions : usage variatoins
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6?>
7--INI--
8precision=14
9--FILE--
10<?php
11/* Prototype: string gettype ( mixed $var );
12   Description: Returns the type of the PHP variable var
13
14   Prototype: bool settype ( mixed &$var, string $type );
15   Description: Set the type of variable var to type
16*/
17
18/* Test usage variation of gettype() and settype() functions:
19         settype() to null type.
20   Set type of the data to "null" and verify using gettype
21   Following are performed in the listed sequence:
22     get the current type of the variable
23     set the type of the variable to "null type"
24     dump the variable to see its new data
25     get the new type of the variable
26*/
27
28/* function to handle catchable errors */
29function foo($errno, $errstr, $errfile, $errline) {
30//	var_dump($errstr);
31   // print error no and error string
32   echo "$errno: $errstr\n";
33}
34//set the error handler, this is required as
35// settype() would fail with catachable fatal error
36set_error_handler("foo");
37
38$var1 = "another string";
39$var2 = array(2,3,4);
40
41// a variable which is unset
42$unset_var = 10.5;
43unset( $unset_var );
44
45class point
46{
47  var $x;
48  var $y;
49
50  function point($x, $y) {
51     $this->x = $x;
52     $this->y = $y;
53  }
54
55  function __toString() {
56     return "ObjectPoint";
57  }
58}
59
60$var_values = array (
61  /* nulls */
62  null,
63
64  /* boolean */
65  FALSE,
66  TRUE,
67  true,
68
69  /* strings */
70  "\xFF",
71  "\x66",
72  "\0123",
73  "",
74  '',
75  " ",
76  ' ',
77  /* numerics in the form of string */
78  '10',
79  "10",
80  "10string",
81  '10string',
82  "1",
83  "-1",
84  "1e2",
85  " 1",
86  "2974394749328742328432",
87  "-1e-2",
88  '1',
89  '-1',
90  '1e2',
91  ' 1',
92  '2974394749328742328432',
93  '-1e-2',
94  "0xff",
95  '0x55',
96  '0XA55',
97  '0X123',
98  "0123",
99  '0123',
100  "-0123",
101  "+0123",
102  '-0123',
103  '+0123',
104  "-0x80001", // invalid numerics as its prefix with sign or have decimal points
105  "+0x80001",
106  "-0x80001.5",
107  "0x80001.5",
108  "@$%#$%^$%^&^",
109
110  /* arrays */
111  array(),
112  array(NULL),
113  array(1,2,3,4),
114  array(1 => "one", 2 => "two", "3" => "three", "four" => 4),
115  array(1.5, 2.4, 6.5e6),
116
117  /* integers */
118  -2147483648, // max -ne int value
119  2147483647,
120  2147483649,
121  1232147483649,
122  0x55,
123  0xF674593039, // a hex value > than max int
124  -0X558F,
125  0555,
126  -0555,
127  02224242434343152, // an octal value > than max int
128
129  /* floats */
130  1e5,
131  -1e5,
132  1E5,
133  -1E5,
134  -1.5,
135  .5,
136  -.5,
137  .5e6,
138  -.5e6,
139  -.5e-6,
140  .5e+6,
141  -.5e+6,
142  .512E6,
143  -.512E6,
144  .512E-6,
145  +.512E-6,
146  .512E+6,
147  -.512E+6,
148
149  new point(NULL, NULL),
150  new point(2.5, 40.5),
151  new point(0, 0),
152
153  /* undefined/unset vars */
154  $unset_var,
155  $undef_var
156);
157
158/* test conversion to null type */
159$type = "null";
160
161echo "\n*** Testing gettype() & settype() functions : usage variations ***\n";
162echo "\n-- Setting type of data to $type --\n";
163$loop_count = 1;
164foreach ($var_values as $var) {
165  echo "-- Iteration $loop_count --\n"; $loop_count++;
166
167  // get the current data type
168  var_dump( gettype($var) );
169
170  // convert it to null
171  var_dump( settype($var, $type) );
172
173  // dump the converted data
174  var_dump( $var );
175
176  // check the new type after conversion
177  var_dump( gettype($var) );
178}
179
180echo "Done\n";
181?>
182--EXPECTF--
1838: Undefined variable: unset_var
1848: Undefined variable: undef_var
185
186*** Testing gettype() & settype() functions : usage variations ***
187
188-- Setting type of data to null --
189-- Iteration 1 --
190string(4) "NULL"
191bool(true)
192NULL
193string(4) "NULL"
194-- Iteration 2 --
195string(7) "boolean"
196bool(true)
197NULL
198string(4) "NULL"
199-- Iteration 3 --
200string(7) "boolean"
201bool(true)
202NULL
203string(4) "NULL"
204-- Iteration 4 --
205string(7) "boolean"
206bool(true)
207NULL
208string(4) "NULL"
209-- Iteration 5 --
210string(6) "string"
211bool(true)
212NULL
213string(4) "NULL"
214-- Iteration 6 --
215string(6) "string"
216bool(true)
217NULL
218string(4) "NULL"
219-- Iteration 7 --
220string(6) "string"
221bool(true)
222NULL
223string(4) "NULL"
224-- Iteration 8 --
225string(6) "string"
226bool(true)
227NULL
228string(4) "NULL"
229-- Iteration 9 --
230string(6) "string"
231bool(true)
232NULL
233string(4) "NULL"
234-- Iteration 10 --
235string(6) "string"
236bool(true)
237NULL
238string(4) "NULL"
239-- Iteration 11 --
240string(6) "string"
241bool(true)
242NULL
243string(4) "NULL"
244-- Iteration 12 --
245string(6) "string"
246bool(true)
247NULL
248string(4) "NULL"
249-- Iteration 13 --
250string(6) "string"
251bool(true)
252NULL
253string(4) "NULL"
254-- Iteration 14 --
255string(6) "string"
256bool(true)
257NULL
258string(4) "NULL"
259-- Iteration 15 --
260string(6) "string"
261bool(true)
262NULL
263string(4) "NULL"
264-- Iteration 16 --
265string(6) "string"
266bool(true)
267NULL
268string(4) "NULL"
269-- Iteration 17 --
270string(6) "string"
271bool(true)
272NULL
273string(4) "NULL"
274-- Iteration 18 --
275string(6) "string"
276bool(true)
277NULL
278string(4) "NULL"
279-- Iteration 19 --
280string(6) "string"
281bool(true)
282NULL
283string(4) "NULL"
284-- Iteration 20 --
285string(6) "string"
286bool(true)
287NULL
288string(4) "NULL"
289-- Iteration 21 --
290string(6) "string"
291bool(true)
292NULL
293string(4) "NULL"
294-- Iteration 22 --
295string(6) "string"
296bool(true)
297NULL
298string(4) "NULL"
299-- Iteration 23 --
300string(6) "string"
301bool(true)
302NULL
303string(4) "NULL"
304-- Iteration 24 --
305string(6) "string"
306bool(true)
307NULL
308string(4) "NULL"
309-- Iteration 25 --
310string(6) "string"
311bool(true)
312NULL
313string(4) "NULL"
314-- Iteration 26 --
315string(6) "string"
316bool(true)
317NULL
318string(4) "NULL"
319-- Iteration 27 --
320string(6) "string"
321bool(true)
322NULL
323string(4) "NULL"
324-- Iteration 28 --
325string(6) "string"
326bool(true)
327NULL
328string(4) "NULL"
329-- Iteration 29 --
330string(6) "string"
331bool(true)
332NULL
333string(4) "NULL"
334-- Iteration 30 --
335string(6) "string"
336bool(true)
337NULL
338string(4) "NULL"
339-- Iteration 31 --
340string(6) "string"
341bool(true)
342NULL
343string(4) "NULL"
344-- Iteration 32 --
345string(6) "string"
346bool(true)
347NULL
348string(4) "NULL"
349-- Iteration 33 --
350string(6) "string"
351bool(true)
352NULL
353string(4) "NULL"
354-- Iteration 34 --
355string(6) "string"
356bool(true)
357NULL
358string(4) "NULL"
359-- Iteration 35 --
360string(6) "string"
361bool(true)
362NULL
363string(4) "NULL"
364-- Iteration 36 --
365string(6) "string"
366bool(true)
367NULL
368string(4) "NULL"
369-- Iteration 37 --
370string(6) "string"
371bool(true)
372NULL
373string(4) "NULL"
374-- Iteration 38 --
375string(6) "string"
376bool(true)
377NULL
378string(4) "NULL"
379-- Iteration 39 --
380string(6) "string"
381bool(true)
382NULL
383string(4) "NULL"
384-- Iteration 40 --
385string(6) "string"
386bool(true)
387NULL
388string(4) "NULL"
389-- Iteration 41 --
390string(6) "string"
391bool(true)
392NULL
393string(4) "NULL"
394-- Iteration 42 --
395string(6) "string"
396bool(true)
397NULL
398string(4) "NULL"
399-- Iteration 43 --
400string(5) "array"
401bool(true)
402NULL
403string(4) "NULL"
404-- Iteration 44 --
405string(5) "array"
406bool(true)
407NULL
408string(4) "NULL"
409-- Iteration 45 --
410string(5) "array"
411bool(true)
412NULL
413string(4) "NULL"
414-- Iteration 46 --
415string(5) "array"
416bool(true)
417NULL
418string(4) "NULL"
419-- Iteration 47 --
420string(5) "array"
421bool(true)
422NULL
423string(4) "NULL"
424-- Iteration 48 --
425string(6) "double"
426bool(true)
427NULL
428string(4) "NULL"
429-- Iteration 49 --
430string(7) "integer"
431bool(true)
432NULL
433string(4) "NULL"
434-- Iteration 50 --
435string(6) "double"
436bool(true)
437NULL
438string(4) "NULL"
439-- Iteration 51 --
440string(6) "double"
441bool(true)
442NULL
443string(4) "NULL"
444-- Iteration 52 --
445string(7) "integer"
446bool(true)
447NULL
448string(4) "NULL"
449-- Iteration 53 --
450string(6) "double"
451bool(true)
452NULL
453string(4) "NULL"
454-- Iteration 54 --
455string(7) "integer"
456bool(true)
457NULL
458string(4) "NULL"
459-- Iteration 55 --
460string(7) "integer"
461bool(true)
462NULL
463string(4) "NULL"
464-- Iteration 56 --
465string(7) "integer"
466bool(true)
467NULL
468string(4) "NULL"
469-- Iteration 57 --
470string(6) "double"
471bool(true)
472NULL
473string(4) "NULL"
474-- Iteration 58 --
475string(6) "double"
476bool(true)
477NULL
478string(4) "NULL"
479-- Iteration 59 --
480string(6) "double"
481bool(true)
482NULL
483string(4) "NULL"
484-- Iteration 60 --
485string(6) "double"
486bool(true)
487NULL
488string(4) "NULL"
489-- Iteration 61 --
490string(6) "double"
491bool(true)
492NULL
493string(4) "NULL"
494-- Iteration 62 --
495string(6) "double"
496bool(true)
497NULL
498string(4) "NULL"
499-- Iteration 63 --
500string(6) "double"
501bool(true)
502NULL
503string(4) "NULL"
504-- Iteration 64 --
505string(6) "double"
506bool(true)
507NULL
508string(4) "NULL"
509-- Iteration 65 --
510string(6) "double"
511bool(true)
512NULL
513string(4) "NULL"
514-- Iteration 66 --
515string(6) "double"
516bool(true)
517NULL
518string(4) "NULL"
519-- Iteration 67 --
520string(6) "double"
521bool(true)
522NULL
523string(4) "NULL"
524-- Iteration 68 --
525string(6) "double"
526bool(true)
527NULL
528string(4) "NULL"
529-- Iteration 69 --
530string(6) "double"
531bool(true)
532NULL
533string(4) "NULL"
534-- Iteration 70 --
535string(6) "double"
536bool(true)
537NULL
538string(4) "NULL"
539-- Iteration 71 --
540string(6) "double"
541bool(true)
542NULL
543string(4) "NULL"
544-- Iteration 72 --
545string(6) "double"
546bool(true)
547NULL
548string(4) "NULL"
549-- Iteration 73 --
550string(6) "double"
551bool(true)
552NULL
553string(4) "NULL"
554-- Iteration 74 --
555string(6) "double"
556bool(true)
557NULL
558string(4) "NULL"
559-- Iteration 75 --
560string(6) "double"
561bool(true)
562NULL
563string(4) "NULL"
564-- Iteration 76 --
565string(6) "object"
566bool(true)
567NULL
568string(4) "NULL"
569-- Iteration 77 --
570string(6) "object"
571bool(true)
572NULL
573string(4) "NULL"
574-- Iteration 78 --
575string(6) "object"
576bool(true)
577NULL
578string(4) "NULL"
579-- Iteration 79 --
580string(4) "NULL"
581bool(true)
582NULL
583string(4) "NULL"
584-- Iteration 80 --
585string(4) "NULL"
586bool(true)
587NULL
588string(4) "NULL"
589Done
590