Annotation of embedaddon/php/ext/standard/tests/general_functions/gettype_settype_variation7.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test gettype() & settype() functions : usage variations
3: --SKIPIF--
4: <?php
5: if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6: ?>
7: --INI--
8: precision=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 object type.
20: Set type of the data to "object" 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 object 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 */
29: function 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
36: set_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;
43: unset( $unset_var );
44:
45: class 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 object type */
159: $type = "object";
160:
161: echo "\n*** Testing gettype() & settype() functions : usage variations ***\n";
162: echo "\n-- Setting type of data to $type --\n";
163: $loop_count = 1;
164: foreach ($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:
180: echo "Done\n";
181: ?>
182: --EXPECTF--
183: 8: Undefined variable: unset_var
184: 8: Undefined variable: undef_var
185:
186: *** Testing gettype() & settype() functions : usage variations ***
187:
188: -- Setting type of data to object --
189: -- Iteration 1 --
190: string(4) "NULL"
191: bool(true)
192: object(stdClass)#4 (0) {
193: }
194: string(6) "object"
195: -- Iteration 2 --
196: string(7) "boolean"
197: bool(true)
198: object(stdClass)#4 (1) {
199: ["scalar"]=>
200: bool(false)
201: }
202: string(6) "object"
203: -- Iteration 3 --
204: string(7) "boolean"
205: bool(true)
206: object(stdClass)#4 (1) {
207: ["scalar"]=>
208: bool(true)
209: }
210: string(6) "object"
211: -- Iteration 4 --
212: string(7) "boolean"
213: bool(true)
214: object(stdClass)#4 (1) {
215: ["scalar"]=>
216: bool(true)
217: }
218: string(6) "object"
219: -- Iteration 5 --
220: string(6) "string"
221: bool(true)
222: object(stdClass)#4 (1) {
223: ["scalar"]=>
224: string(1) "ÿ"
225: }
226: string(6) "object"
227: -- Iteration 6 --
228: string(6) "string"
229: bool(true)
230: object(stdClass)#4 (1) {
231: ["scalar"]=>
232: string(1) "f"
233: }
234: string(6) "object"
235: -- Iteration 7 --
236: string(6) "string"
237: bool(true)
238: object(stdClass)#4 (1) {
239: ["scalar"]=>
240: string(2) "
241: 3"
242: }
243: string(6) "object"
244: -- Iteration 8 --
245: string(6) "string"
246: bool(true)
247: object(stdClass)#4 (1) {
248: ["scalar"]=>
249: string(0) ""
250: }
251: string(6) "object"
252: -- Iteration 9 --
253: string(6) "string"
254: bool(true)
255: object(stdClass)#4 (1) {
256: ["scalar"]=>
257: string(0) ""
258: }
259: string(6) "object"
260: -- Iteration 10 --
261: string(6) "string"
262: bool(true)
263: object(stdClass)#4 (1) {
264: ["scalar"]=>
265: string(1) " "
266: }
267: string(6) "object"
268: -- Iteration 11 --
269: string(6) "string"
270: bool(true)
271: object(stdClass)#4 (1) {
272: ["scalar"]=>
273: string(1) " "
274: }
275: string(6) "object"
276: -- Iteration 12 --
277: string(6) "string"
278: bool(true)
279: object(stdClass)#4 (1) {
280: ["scalar"]=>
281: string(2) "10"
282: }
283: string(6) "object"
284: -- Iteration 13 --
285: string(6) "string"
286: bool(true)
287: object(stdClass)#4 (1) {
288: ["scalar"]=>
289: string(2) "10"
290: }
291: string(6) "object"
292: -- Iteration 14 --
293: string(6) "string"
294: bool(true)
295: object(stdClass)#4 (1) {
296: ["scalar"]=>
297: string(8) "10string"
298: }
299: string(6) "object"
300: -- Iteration 15 --
301: string(6) "string"
302: bool(true)
303: object(stdClass)#4 (1) {
304: ["scalar"]=>
305: string(8) "10string"
306: }
307: string(6) "object"
308: -- Iteration 16 --
309: string(6) "string"
310: bool(true)
311: object(stdClass)#4 (1) {
312: ["scalar"]=>
313: string(1) "1"
314: }
315: string(6) "object"
316: -- Iteration 17 --
317: string(6) "string"
318: bool(true)
319: object(stdClass)#4 (1) {
320: ["scalar"]=>
321: string(2) "-1"
322: }
323: string(6) "object"
324: -- Iteration 18 --
325: string(6) "string"
326: bool(true)
327: object(stdClass)#4 (1) {
328: ["scalar"]=>
329: string(3) "1e2"
330: }
331: string(6) "object"
332: -- Iteration 19 --
333: string(6) "string"
334: bool(true)
335: object(stdClass)#4 (1) {
336: ["scalar"]=>
337: string(2) " 1"
338: }
339: string(6) "object"
340: -- Iteration 20 --
341: string(6) "string"
342: bool(true)
343: object(stdClass)#4 (1) {
344: ["scalar"]=>
345: string(22) "2974394749328742328432"
346: }
347: string(6) "object"
348: -- Iteration 21 --
349: string(6) "string"
350: bool(true)
351: object(stdClass)#4 (1) {
352: ["scalar"]=>
353: string(5) "-1e-2"
354: }
355: string(6) "object"
356: -- Iteration 22 --
357: string(6) "string"
358: bool(true)
359: object(stdClass)#4 (1) {
360: ["scalar"]=>
361: string(1) "1"
362: }
363: string(6) "object"
364: -- Iteration 23 --
365: string(6) "string"
366: bool(true)
367: object(stdClass)#4 (1) {
368: ["scalar"]=>
369: string(2) "-1"
370: }
371: string(6) "object"
372: -- Iteration 24 --
373: string(6) "string"
374: bool(true)
375: object(stdClass)#4 (1) {
376: ["scalar"]=>
377: string(3) "1e2"
378: }
379: string(6) "object"
380: -- Iteration 25 --
381: string(6) "string"
382: bool(true)
383: object(stdClass)#4 (1) {
384: ["scalar"]=>
385: string(2) " 1"
386: }
387: string(6) "object"
388: -- Iteration 26 --
389: string(6) "string"
390: bool(true)
391: object(stdClass)#4 (1) {
392: ["scalar"]=>
393: string(22) "2974394749328742328432"
394: }
395: string(6) "object"
396: -- Iteration 27 --
397: string(6) "string"
398: bool(true)
399: object(stdClass)#4 (1) {
400: ["scalar"]=>
401: string(5) "-1e-2"
402: }
403: string(6) "object"
404: -- Iteration 28 --
405: string(6) "string"
406: bool(true)
407: object(stdClass)#4 (1) {
408: ["scalar"]=>
409: string(4) "0xff"
410: }
411: string(6) "object"
412: -- Iteration 29 --
413: string(6) "string"
414: bool(true)
415: object(stdClass)#4 (1) {
416: ["scalar"]=>
417: string(4) "0x55"
418: }
419: string(6) "object"
420: -- Iteration 30 --
421: string(6) "string"
422: bool(true)
423: object(stdClass)#4 (1) {
424: ["scalar"]=>
425: string(5) "0XA55"
426: }
427: string(6) "object"
428: -- Iteration 31 --
429: string(6) "string"
430: bool(true)
431: object(stdClass)#4 (1) {
432: ["scalar"]=>
433: string(5) "0X123"
434: }
435: string(6) "object"
436: -- Iteration 32 --
437: string(6) "string"
438: bool(true)
439: object(stdClass)#4 (1) {
440: ["scalar"]=>
441: string(4) "0123"
442: }
443: string(6) "object"
444: -- Iteration 33 --
445: string(6) "string"
446: bool(true)
447: object(stdClass)#4 (1) {
448: ["scalar"]=>
449: string(4) "0123"
450: }
451: string(6) "object"
452: -- Iteration 34 --
453: string(6) "string"
454: bool(true)
455: object(stdClass)#4 (1) {
456: ["scalar"]=>
457: string(5) "-0123"
458: }
459: string(6) "object"
460: -- Iteration 35 --
461: string(6) "string"
462: bool(true)
463: object(stdClass)#4 (1) {
464: ["scalar"]=>
465: string(5) "+0123"
466: }
467: string(6) "object"
468: -- Iteration 36 --
469: string(6) "string"
470: bool(true)
471: object(stdClass)#4 (1) {
472: ["scalar"]=>
473: string(5) "-0123"
474: }
475: string(6) "object"
476: -- Iteration 37 --
477: string(6) "string"
478: bool(true)
479: object(stdClass)#4 (1) {
480: ["scalar"]=>
481: string(5) "+0123"
482: }
483: string(6) "object"
484: -- Iteration 38 --
485: string(6) "string"
486: bool(true)
487: object(stdClass)#4 (1) {
488: ["scalar"]=>
489: string(8) "-0x80001"
490: }
491: string(6) "object"
492: -- Iteration 39 --
493: string(6) "string"
494: bool(true)
495: object(stdClass)#4 (1) {
496: ["scalar"]=>
497: string(8) "+0x80001"
498: }
499: string(6) "object"
500: -- Iteration 40 --
501: string(6) "string"
502: bool(true)
503: object(stdClass)#4 (1) {
504: ["scalar"]=>
505: string(10) "-0x80001.5"
506: }
507: string(6) "object"
508: -- Iteration 41 --
509: string(6) "string"
510: bool(true)
511: object(stdClass)#4 (1) {
512: ["scalar"]=>
513: string(9) "0x80001.5"
514: }
515: string(6) "object"
516: -- Iteration 42 --
517: string(6) "string"
518: bool(true)
519: object(stdClass)#4 (1) {
520: ["scalar"]=>
521: string(12) "@$%#$%^$%^&^"
522: }
523: string(6) "object"
524: -- Iteration 43 --
525: string(5) "array"
526: bool(true)
527: object(stdClass)#4 (0) {
528: }
529: string(6) "object"
530: -- Iteration 44 --
531: string(5) "array"
532: bool(true)
533: object(stdClass)#4 (1) {
534: [0]=>
535: NULL
536: }
537: string(6) "object"
538: -- Iteration 45 --
539: string(5) "array"
540: bool(true)
541: object(stdClass)#4 (4) {
542: [0]=>
543: int(1)
544: [1]=>
545: int(2)
546: [2]=>
547: int(3)
548: [3]=>
549: int(4)
550: }
551: string(6) "object"
552: -- Iteration 46 --
553: string(5) "array"
554: bool(true)
555: object(stdClass)#4 (4) {
556: [1]=>
557: string(3) "one"
558: [2]=>
559: string(3) "two"
560: [3]=>
561: string(5) "three"
562: ["four"]=>
563: int(4)
564: }
565: string(6) "object"
566: -- Iteration 47 --
567: string(5) "array"
568: bool(true)
569: object(stdClass)#4 (3) {
570: [0]=>
571: float(1.5)
572: [1]=>
573: float(2.4)
574: [2]=>
575: float(6500000)
576: }
577: string(6) "object"
578: -- Iteration 48 --
579: string(6) "double"
580: bool(true)
581: object(stdClass)#4 (1) {
582: ["scalar"]=>
583: float(-2147483648)
584: }
585: string(6) "object"
586: -- Iteration 49 --
587: string(7) "integer"
588: bool(true)
589: object(stdClass)#4 (1) {
590: ["scalar"]=>
591: int(2147483647)
592: }
593: string(6) "object"
594: -- Iteration 50 --
595: string(6) "double"
596: bool(true)
597: object(stdClass)#4 (1) {
598: ["scalar"]=>
599: float(2147483649)
600: }
601: string(6) "object"
602: -- Iteration 51 --
603: string(6) "double"
604: bool(true)
605: object(stdClass)#4 (1) {
606: ["scalar"]=>
607: float(1232147483649)
608: }
609: string(6) "object"
610: -- Iteration 52 --
611: string(7) "integer"
612: bool(true)
613: object(stdClass)#4 (1) {
614: ["scalar"]=>
615: int(85)
616: }
617: string(6) "object"
618: -- Iteration 53 --
619: string(6) "double"
620: bool(true)
621: object(stdClass)#4 (1) {
622: ["scalar"]=>
623: float(1058513956921)
624: }
625: string(6) "object"
626: -- Iteration 54 --
627: string(7) "integer"
628: bool(true)
629: object(stdClass)#4 (1) {
630: ["scalar"]=>
631: int(-21903)
632: }
633: string(6) "object"
634: -- Iteration 55 --
635: string(7) "integer"
636: bool(true)
637: object(stdClass)#4 (1) {
638: ["scalar"]=>
639: int(365)
640: }
641: string(6) "object"
642: -- Iteration 56 --
643: string(7) "integer"
644: bool(true)
645: object(stdClass)#4 (1) {
646: ["scalar"]=>
647: int(-365)
648: }
649: string(6) "object"
650: -- Iteration 57 --
651: string(6) "double"
652: bool(true)
653: object(stdClass)#4 (1) {
654: ["scalar"]=>
655: float(80561044571754)
656: }
657: string(6) "object"
658: -- Iteration 58 --
659: string(6) "double"
660: bool(true)
661: object(stdClass)#4 (1) {
662: ["scalar"]=>
663: float(100000)
664: }
665: string(6) "object"
666: -- Iteration 59 --
667: string(6) "double"
668: bool(true)
669: object(stdClass)#4 (1) {
670: ["scalar"]=>
671: float(-100000)
672: }
673: string(6) "object"
674: -- Iteration 60 --
675: string(6) "double"
676: bool(true)
677: object(stdClass)#4 (1) {
678: ["scalar"]=>
679: float(100000)
680: }
681: string(6) "object"
682: -- Iteration 61 --
683: string(6) "double"
684: bool(true)
685: object(stdClass)#4 (1) {
686: ["scalar"]=>
687: float(-100000)
688: }
689: string(6) "object"
690: -- Iteration 62 --
691: string(6) "double"
692: bool(true)
693: object(stdClass)#4 (1) {
694: ["scalar"]=>
695: float(-1.5)
696: }
697: string(6) "object"
698: -- Iteration 63 --
699: string(6) "double"
700: bool(true)
701: object(stdClass)#4 (1) {
702: ["scalar"]=>
703: float(0.5)
704: }
705: string(6) "object"
706: -- Iteration 64 --
707: string(6) "double"
708: bool(true)
709: object(stdClass)#4 (1) {
710: ["scalar"]=>
711: float(-0.5)
712: }
713: string(6) "object"
714: -- Iteration 65 --
715: string(6) "double"
716: bool(true)
717: object(stdClass)#4 (1) {
718: ["scalar"]=>
719: float(500000)
720: }
721: string(6) "object"
722: -- Iteration 66 --
723: string(6) "double"
724: bool(true)
725: object(stdClass)#4 (1) {
726: ["scalar"]=>
727: float(-500000)
728: }
729: string(6) "object"
730: -- Iteration 67 --
731: string(6) "double"
732: bool(true)
733: object(stdClass)#4 (1) {
734: ["scalar"]=>
735: float(-5.0E-7)
736: }
737: string(6) "object"
738: -- Iteration 68 --
739: string(6) "double"
740: bool(true)
741: object(stdClass)#4 (1) {
742: ["scalar"]=>
743: float(500000)
744: }
745: string(6) "object"
746: -- Iteration 69 --
747: string(6) "double"
748: bool(true)
749: object(stdClass)#4 (1) {
750: ["scalar"]=>
751: float(-500000)
752: }
753: string(6) "object"
754: -- Iteration 70 --
755: string(6) "double"
756: bool(true)
757: object(stdClass)#4 (1) {
758: ["scalar"]=>
759: float(512000)
760: }
761: string(6) "object"
762: -- Iteration 71 --
763: string(6) "double"
764: bool(true)
765: object(stdClass)#4 (1) {
766: ["scalar"]=>
767: float(-512000)
768: }
769: string(6) "object"
770: -- Iteration 72 --
771: string(6) "double"
772: bool(true)
773: object(stdClass)#4 (1) {
774: ["scalar"]=>
775: float(5.12E-7)
776: }
777: string(6) "object"
778: -- Iteration 73 --
779: string(6) "double"
780: bool(true)
781: object(stdClass)#4 (1) {
782: ["scalar"]=>
783: float(5.12E-7)
784: }
785: string(6) "object"
786: -- Iteration 74 --
787: string(6) "double"
788: bool(true)
789: object(stdClass)#4 (1) {
790: ["scalar"]=>
791: float(512000)
792: }
793: string(6) "object"
794: -- Iteration 75 --
795: string(6) "double"
796: bool(true)
797: object(stdClass)#4 (1) {
798: ["scalar"]=>
799: float(-512000)
800: }
801: string(6) "object"
802: -- Iteration 76 --
803: string(6) "object"
804: bool(true)
805: object(point)#1 (2) {
806: ["x"]=>
807: NULL
808: ["y"]=>
809: NULL
810: }
811: string(6) "object"
812: -- Iteration 77 --
813: string(6) "object"
814: bool(true)
815: object(point)#2 (2) {
816: ["x"]=>
817: float(2.5)
818: ["y"]=>
819: float(40.5)
820: }
821: string(6) "object"
822: -- Iteration 78 --
823: string(6) "object"
824: bool(true)
825: object(point)#3 (2) {
826: ["x"]=>
827: int(0)
828: ["y"]=>
829: int(0)
830: }
831: string(6) "object"
832: -- Iteration 79 --
833: string(4) "NULL"
834: bool(true)
835: object(stdClass)#4 (0) {
836: }
837: string(6) "object"
838: -- Iteration 80 --
839: string(4) "NULL"
840: bool(true)
841: object(stdClass)#4 (0) {
842: }
843: string(6) "object"
844: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>