Annotation of embedaddon/php/ext/standard/tests/general_functions/gettype_settype_variation2.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: if ( strtoupper( substr(PHP_OS, 0, 3) ) == 'MAC' ) {
8: die('skip Do not run on MacOS');
9: }
10: --INI--
11: precision=14
12: --FILE--
13: <?php
14: /* Prototype: string gettype ( mixed $var );
15: Description: Returns the type of the PHP variable var
16:
17: Prototype: bool settype ( mixed &$var, string $type );
18: Description: Set the type of variable var to type
19: */
20:
21: /* Test usage variation of gettype() and settype() functions:
22: settype() to int/integer type.
23: Set type of the data to "int"/"integer" and verify using gettype
24: Following are performed in the listed sequence:
25: get the current type of the variable
26: set the type of the variable to interger/int type
27: dump the variable to see its new data
28: get the new type of the variable
29: */
30:
31: /* function to handle catchable errors */
32: function foo($errno, $errstr, $errfile, $errline) {
33: // var_dump($errstr);
34: // print error no and error string
35: echo "$errno: $errstr\n";
36: }
37: //set the error handler, this is required as
38: // settype() would fail with catachable fatal error
39: set_error_handler("foo");
40:
41: $var1 = "another string";
42: $var2 = array(2,3,4);
43:
44: // a variable which is unset
45: $unset_var = 10.5;
46: unset( $unset_var );
47:
48: class point
49: {
50: var $x;
51: var $y;
52:
53: function point($x, $y) {
54: $this->x = $x;
55: $this->y = $y;
56: }
57:
58: function __toString() {
59: return "ObjectPoint";
60: }
61: }
62:
63: $var_values = array (
64: /* nulls */
65: null,
66:
67: /* boolean */
68: FALSE,
69: TRUE,
70: true,
71:
72: /* strings */
73: "\xFF",
74: "\x66",
75: "\0123",
76: "",
77: '',
78: " ",
79: ' ',
80: /* numerics in the form of string */
81: '10',
82: "10",
83: "10string",
84: '10string',
85: "1",
86: "-1",
87: "1e2",
88: " 1",
89: "2974394749328742328432",
90: "-1e-2",
91: '1',
92: '-1',
93: '1e2',
94: ' 1',
95: '2974394749328742328432',
96: '-1e-2',
97: "0xff",
98: '0x55',
99: '0XA55',
100: '0X123',
101: "0123",
102: '0123',
103: "-0123",
104: "+0123",
105: '-0123',
106: '+0123',
107: "-0x80001", // invalid numerics as its prefix with sign or have decimal points
108: "+0x80001",
109: "-0x80001.5",
110: "0x80001.5",
111: "@$%#$%^$%^&^",
112:
113: /* arrays */
114: array(),
115: array(NULL),
116: array(1,2,3,4),
117: array(1 => "one", 2 => "two", "3" => "three", "four" => 4),
118: array(1.5, 2.4, 6.5e6),
119:
120: /* integers */
121: -2147483648, // max -ne int value
122: 2147483647,
123: 2147483649,
124: 1232147483649,
125: 0x55,
126: 0xF674593039, // a hex value > than max int
127: -0X558F,
128: 0555,
129: -0555,
130: 02224242434343152, // an octal value > than max int
131:
132: /* floats */
133: 1e5,
134: -1e5,
135: 1E5,
136: -1E5,
137: -1.5,
138: .5,
139: -.5,
140: .5e6,
141: -.5e6,
142: -.5e-6,
143: .5e+6,
144: -.5e+6,
145: .512E6,
146: -.512E6,
147: .512E-6,
148: +.512E-6,
149: .512E+6,
150: -.512E+6,
151:
152: new point(NULL, NULL),
153: new point(2.5, 40.5),
154: new point(0, 0),
155:
156: /* undefined/unset vars */
157: $unset_var,
158: $undef_var
159: );
160:
161: // test conversion to these types
162: $types = array(
163: "integer",
164: "int"
165: );
166:
167: echo "\n*** Testing settype() & gettype() : usage variations ***\n";
168: foreach ($types as $type) {
169: echo "\n-- Setting type of data to $type --\n";
170: $inner_loop_count = 1;
171: foreach ($var_values as $var) {
172: echo "-- Iteration $inner_loop_count --\n"; $inner_loop_count++;
173:
174: // get the current data type
175: var_dump( gettype($var) );
176:
177: // convert it to new type
178: var_dump( settype($var, $type) );
179:
180: // dump the converted $var
181: var_dump( $var );
182:
183: // get the new type of the $var
184: var_dump( gettype($var) );
185: }
186: }
187:
188: echo "Done\n";
189: ?>
190: --EXPECTF--
191: 8: Undefined variable: unset_var
192: 8: Undefined variable: undef_var
193:
194: *** Testing settype() & gettype() : usage variations ***
195:
196: -- Setting type of data to integer --
197: -- Iteration 1 --
198: string(4) "NULL"
199: bool(true)
200: int(0)
201: string(7) "integer"
202: -- Iteration 2 --
203: string(7) "boolean"
204: bool(true)
205: int(0)
206: string(7) "integer"
207: -- Iteration 3 --
208: string(7) "boolean"
209: bool(true)
210: int(1)
211: string(7) "integer"
212: -- Iteration 4 --
213: string(7) "boolean"
214: bool(true)
215: int(1)
216: string(7) "integer"
217: -- Iteration 5 --
218: string(6) "string"
219: bool(true)
220: int(0)
221: string(7) "integer"
222: -- Iteration 6 --
223: string(6) "string"
224: bool(true)
225: int(0)
226: string(7) "integer"
227: -- Iteration 7 --
228: string(6) "string"
229: bool(true)
230: int(3)
231: string(7) "integer"
232: -- Iteration 8 --
233: string(6) "string"
234: bool(true)
235: int(0)
236: string(7) "integer"
237: -- Iteration 9 --
238: string(6) "string"
239: bool(true)
240: int(0)
241: string(7) "integer"
242: -- Iteration 10 --
243: string(6) "string"
244: bool(true)
245: int(0)
246: string(7) "integer"
247: -- Iteration 11 --
248: string(6) "string"
249: bool(true)
250: int(0)
251: string(7) "integer"
252: -- Iteration 12 --
253: string(6) "string"
254: bool(true)
255: int(10)
256: string(7) "integer"
257: -- Iteration 13 --
258: string(6) "string"
259: bool(true)
260: int(10)
261: string(7) "integer"
262: -- Iteration 14 --
263: string(6) "string"
264: bool(true)
265: int(10)
266: string(7) "integer"
267: -- Iteration 15 --
268: string(6) "string"
269: bool(true)
270: int(10)
271: string(7) "integer"
272: -- Iteration 16 --
273: string(6) "string"
274: bool(true)
275: int(1)
276: string(7) "integer"
277: -- Iteration 17 --
278: string(6) "string"
279: bool(true)
280: int(-1)
281: string(7) "integer"
282: -- Iteration 18 --
283: string(6) "string"
284: bool(true)
285: int(1)
286: string(7) "integer"
287: -- Iteration 19 --
288: string(6) "string"
289: bool(true)
290: int(1)
291: string(7) "integer"
292: -- Iteration 20 --
293: string(6) "string"
294: bool(true)
295: int(2147483647)
296: string(7) "integer"
297: -- Iteration 21 --
298: string(6) "string"
299: bool(true)
300: int(-1)
301: string(7) "integer"
302: -- Iteration 22 --
303: string(6) "string"
304: bool(true)
305: int(1)
306: string(7) "integer"
307: -- Iteration 23 --
308: string(6) "string"
309: bool(true)
310: int(-1)
311: string(7) "integer"
312: -- Iteration 24 --
313: string(6) "string"
314: bool(true)
315: int(1)
316: string(7) "integer"
317: -- Iteration 25 --
318: string(6) "string"
319: bool(true)
320: int(1)
321: string(7) "integer"
322: -- Iteration 26 --
323: string(6) "string"
324: bool(true)
325: int(2147483647)
326: string(7) "integer"
327: -- Iteration 27 --
328: string(6) "string"
329: bool(true)
330: int(-1)
331: string(7) "integer"
332: -- Iteration 28 --
333: string(6) "string"
334: bool(true)
335: int(0)
336: string(7) "integer"
337: -- Iteration 29 --
338: string(6) "string"
339: bool(true)
340: int(0)
341: string(7) "integer"
342: -- Iteration 30 --
343: string(6) "string"
344: bool(true)
345: int(0)
346: string(7) "integer"
347: -- Iteration 31 --
348: string(6) "string"
349: bool(true)
350: int(0)
351: string(7) "integer"
352: -- Iteration 32 --
353: string(6) "string"
354: bool(true)
355: int(123)
356: string(7) "integer"
357: -- Iteration 33 --
358: string(6) "string"
359: bool(true)
360: int(123)
361: string(7) "integer"
362: -- Iteration 34 --
363: string(6) "string"
364: bool(true)
365: int(-123)
366: string(7) "integer"
367: -- Iteration 35 --
368: string(6) "string"
369: bool(true)
370: int(123)
371: string(7) "integer"
372: -- Iteration 36 --
373: string(6) "string"
374: bool(true)
375: int(-123)
376: string(7) "integer"
377: -- Iteration 37 --
378: string(6) "string"
379: bool(true)
380: int(123)
381: string(7) "integer"
382: -- Iteration 38 --
383: string(6) "string"
384: bool(true)
385: int(0)
386: string(7) "integer"
387: -- Iteration 39 --
388: string(6) "string"
389: bool(true)
390: int(0)
391: string(7) "integer"
392: -- Iteration 40 --
393: string(6) "string"
394: bool(true)
395: int(0)
396: string(7) "integer"
397: -- Iteration 41 --
398: string(6) "string"
399: bool(true)
400: int(0)
401: string(7) "integer"
402: -- Iteration 42 --
403: string(6) "string"
404: bool(true)
405: int(0)
406: string(7) "integer"
407: -- Iteration 43 --
408: string(5) "array"
409: bool(true)
410: int(0)
411: string(7) "integer"
412: -- Iteration 44 --
413: string(5) "array"
414: bool(true)
415: int(1)
416: string(7) "integer"
417: -- Iteration 45 --
418: string(5) "array"
419: bool(true)
420: int(1)
421: string(7) "integer"
422: -- Iteration 46 --
423: string(5) "array"
424: bool(true)
425: int(1)
426: string(7) "integer"
427: -- Iteration 47 --
428: string(5) "array"
429: bool(true)
430: int(1)
431: string(7) "integer"
432: -- Iteration 48 --
433: string(6) "double"
434: bool(true)
435: int(-2147483648)
436: string(7) "integer"
437: -- Iteration 49 --
438: string(7) "integer"
439: bool(true)
440: int(2147483647)
441: string(7) "integer"
442: -- Iteration 50 --
443: string(6) "double"
444: bool(true)
445: int(-2147483647)
446: string(7) "integer"
447: -- Iteration 51 --
448: string(6) "double"
449: bool(true)
450: int(-508130303)
451: string(7) "integer"
452: -- Iteration 52 --
453: string(7) "integer"
454: bool(true)
455: int(85)
456: string(7) "integer"
457: -- Iteration 53 --
458: string(6) "double"
459: bool(true)
460: int(1952002105)
461: string(7) "integer"
462: -- Iteration 54 --
463: string(7) "integer"
464: bool(true)
465: int(-21903)
466: string(7) "integer"
467: -- Iteration 55 --
468: string(7) "integer"
469: bool(true)
470: int(365)
471: string(7) "integer"
472: -- Iteration 56 --
473: string(7) "integer"
474: bool(true)
475: int(-365)
476: string(7) "integer"
477: -- Iteration 57 --
478: string(6) "double"
479: bool(true)
480: int(343000682)
481: string(7) "integer"
482: -- Iteration 58 --
483: string(6) "double"
484: bool(true)
485: int(100000)
486: string(7) "integer"
487: -- Iteration 59 --
488: string(6) "double"
489: bool(true)
490: int(-100000)
491: string(7) "integer"
492: -- Iteration 60 --
493: string(6) "double"
494: bool(true)
495: int(100000)
496: string(7) "integer"
497: -- Iteration 61 --
498: string(6) "double"
499: bool(true)
500: int(-100000)
501: string(7) "integer"
502: -- Iteration 62 --
503: string(6) "double"
504: bool(true)
505: int(-1)
506: string(7) "integer"
507: -- Iteration 63 --
508: string(6) "double"
509: bool(true)
510: int(0)
511: string(7) "integer"
512: -- Iteration 64 --
513: string(6) "double"
514: bool(true)
515: int(0)
516: string(7) "integer"
517: -- Iteration 65 --
518: string(6) "double"
519: bool(true)
520: int(500000)
521: string(7) "integer"
522: -- Iteration 66 --
523: string(6) "double"
524: bool(true)
525: int(-500000)
526: string(7) "integer"
527: -- Iteration 67 --
528: string(6) "double"
529: bool(true)
530: int(0)
531: string(7) "integer"
532: -- Iteration 68 --
533: string(6) "double"
534: bool(true)
535: int(500000)
536: string(7) "integer"
537: -- Iteration 69 --
538: string(6) "double"
539: bool(true)
540: int(-500000)
541: string(7) "integer"
542: -- Iteration 70 --
543: string(6) "double"
544: bool(true)
545: int(512000)
546: string(7) "integer"
547: -- Iteration 71 --
548: string(6) "double"
549: bool(true)
550: int(-512000)
551: string(7) "integer"
552: -- Iteration 72 --
553: string(6) "double"
554: bool(true)
555: int(0)
556: string(7) "integer"
557: -- Iteration 73 --
558: string(6) "double"
559: bool(true)
560: int(0)
561: string(7) "integer"
562: -- Iteration 74 --
563: string(6) "double"
564: bool(true)
565: int(512000)
566: string(7) "integer"
567: -- Iteration 75 --
568: string(6) "double"
569: bool(true)
570: int(-512000)
571: string(7) "integer"
572: -- Iteration 76 --
573: string(6) "object"
574: 8: Object of class point could not be converted to int
575: bool(true)
576: int(1)
577: string(7) "integer"
578: -- Iteration 77 --
579: string(6) "object"
580: 8: Object of class point could not be converted to int
581: bool(true)
582: int(1)
583: string(7) "integer"
584: -- Iteration 78 --
585: string(6) "object"
586: 8: Object of class point could not be converted to int
587: bool(true)
588: int(1)
589: string(7) "integer"
590: -- Iteration 79 --
591: string(4) "NULL"
592: bool(true)
593: int(0)
594: string(7) "integer"
595: -- Iteration 80 --
596: string(4) "NULL"
597: bool(true)
598: int(0)
599: string(7) "integer"
600:
601: -- Setting type of data to int --
602: -- Iteration 1 --
603: string(4) "NULL"
604: bool(true)
605: int(0)
606: string(7) "integer"
607: -- Iteration 2 --
608: string(7) "boolean"
609: bool(true)
610: int(0)
611: string(7) "integer"
612: -- Iteration 3 --
613: string(7) "boolean"
614: bool(true)
615: int(1)
616: string(7) "integer"
617: -- Iteration 4 --
618: string(7) "boolean"
619: bool(true)
620: int(1)
621: string(7) "integer"
622: -- Iteration 5 --
623: string(6) "string"
624: bool(true)
625: int(0)
626: string(7) "integer"
627: -- Iteration 6 --
628: string(6) "string"
629: bool(true)
630: int(0)
631: string(7) "integer"
632: -- Iteration 7 --
633: string(6) "string"
634: bool(true)
635: int(3)
636: string(7) "integer"
637: -- Iteration 8 --
638: string(6) "string"
639: bool(true)
640: int(0)
641: string(7) "integer"
642: -- Iteration 9 --
643: string(6) "string"
644: bool(true)
645: int(0)
646: string(7) "integer"
647: -- Iteration 10 --
648: string(6) "string"
649: bool(true)
650: int(0)
651: string(7) "integer"
652: -- Iteration 11 --
653: string(6) "string"
654: bool(true)
655: int(0)
656: string(7) "integer"
657: -- Iteration 12 --
658: string(6) "string"
659: bool(true)
660: int(10)
661: string(7) "integer"
662: -- Iteration 13 --
663: string(6) "string"
664: bool(true)
665: int(10)
666: string(7) "integer"
667: -- Iteration 14 --
668: string(6) "string"
669: bool(true)
670: int(10)
671: string(7) "integer"
672: -- Iteration 15 --
673: string(6) "string"
674: bool(true)
675: int(10)
676: string(7) "integer"
677: -- Iteration 16 --
678: string(6) "string"
679: bool(true)
680: int(1)
681: string(7) "integer"
682: -- Iteration 17 --
683: string(6) "string"
684: bool(true)
685: int(-1)
686: string(7) "integer"
687: -- Iteration 18 --
688: string(6) "string"
689: bool(true)
690: int(1)
691: string(7) "integer"
692: -- Iteration 19 --
693: string(6) "string"
694: bool(true)
695: int(1)
696: string(7) "integer"
697: -- Iteration 20 --
698: string(6) "string"
699: bool(true)
700: int(2147483647)
701: string(7) "integer"
702: -- Iteration 21 --
703: string(6) "string"
704: bool(true)
705: int(-1)
706: string(7) "integer"
707: -- Iteration 22 --
708: string(6) "string"
709: bool(true)
710: int(1)
711: string(7) "integer"
712: -- Iteration 23 --
713: string(6) "string"
714: bool(true)
715: int(-1)
716: string(7) "integer"
717: -- Iteration 24 --
718: string(6) "string"
719: bool(true)
720: int(1)
721: string(7) "integer"
722: -- Iteration 25 --
723: string(6) "string"
724: bool(true)
725: int(1)
726: string(7) "integer"
727: -- Iteration 26 --
728: string(6) "string"
729: bool(true)
730: int(2147483647)
731: string(7) "integer"
732: -- Iteration 27 --
733: string(6) "string"
734: bool(true)
735: int(-1)
736: string(7) "integer"
737: -- Iteration 28 --
738: string(6) "string"
739: bool(true)
740: int(0)
741: string(7) "integer"
742: -- Iteration 29 --
743: string(6) "string"
744: bool(true)
745: int(0)
746: string(7) "integer"
747: -- Iteration 30 --
748: string(6) "string"
749: bool(true)
750: int(0)
751: string(7) "integer"
752: -- Iteration 31 --
753: string(6) "string"
754: bool(true)
755: int(0)
756: string(7) "integer"
757: -- Iteration 32 --
758: string(6) "string"
759: bool(true)
760: int(123)
761: string(7) "integer"
762: -- Iteration 33 --
763: string(6) "string"
764: bool(true)
765: int(123)
766: string(7) "integer"
767: -- Iteration 34 --
768: string(6) "string"
769: bool(true)
770: int(-123)
771: string(7) "integer"
772: -- Iteration 35 --
773: string(6) "string"
774: bool(true)
775: int(123)
776: string(7) "integer"
777: -- Iteration 36 --
778: string(6) "string"
779: bool(true)
780: int(-123)
781: string(7) "integer"
782: -- Iteration 37 --
783: string(6) "string"
784: bool(true)
785: int(123)
786: string(7) "integer"
787: -- Iteration 38 --
788: string(6) "string"
789: bool(true)
790: int(0)
791: string(7) "integer"
792: -- Iteration 39 --
793: string(6) "string"
794: bool(true)
795: int(0)
796: string(7) "integer"
797: -- Iteration 40 --
798: string(6) "string"
799: bool(true)
800: int(0)
801: string(7) "integer"
802: -- Iteration 41 --
803: string(6) "string"
804: bool(true)
805: int(0)
806: string(7) "integer"
807: -- Iteration 42 --
808: string(6) "string"
809: bool(true)
810: int(0)
811: string(7) "integer"
812: -- Iteration 43 --
813: string(5) "array"
814: bool(true)
815: int(0)
816: string(7) "integer"
817: -- Iteration 44 --
818: string(5) "array"
819: bool(true)
820: int(1)
821: string(7) "integer"
822: -- Iteration 45 --
823: string(5) "array"
824: bool(true)
825: int(1)
826: string(7) "integer"
827: -- Iteration 46 --
828: string(5) "array"
829: bool(true)
830: int(1)
831: string(7) "integer"
832: -- Iteration 47 --
833: string(5) "array"
834: bool(true)
835: int(1)
836: string(7) "integer"
837: -- Iteration 48 --
838: string(6) "double"
839: bool(true)
840: int(-2147483648)
841: string(7) "integer"
842: -- Iteration 49 --
843: string(7) "integer"
844: bool(true)
845: int(2147483647)
846: string(7) "integer"
847: -- Iteration 50 --
848: string(6) "double"
849: bool(true)
850: int(-2147483647)
851: string(7) "integer"
852: -- Iteration 51 --
853: string(6) "double"
854: bool(true)
855: int(-508130303)
856: string(7) "integer"
857: -- Iteration 52 --
858: string(7) "integer"
859: bool(true)
860: int(85)
861: string(7) "integer"
862: -- Iteration 53 --
863: string(6) "double"
864: bool(true)
865: int(1952002105)
866: string(7) "integer"
867: -- Iteration 54 --
868: string(7) "integer"
869: bool(true)
870: int(-21903)
871: string(7) "integer"
872: -- Iteration 55 --
873: string(7) "integer"
874: bool(true)
875: int(365)
876: string(7) "integer"
877: -- Iteration 56 --
878: string(7) "integer"
879: bool(true)
880: int(-365)
881: string(7) "integer"
882: -- Iteration 57 --
883: string(6) "double"
884: bool(true)
885: int(343000682)
886: string(7) "integer"
887: -- Iteration 58 --
888: string(6) "double"
889: bool(true)
890: int(100000)
891: string(7) "integer"
892: -- Iteration 59 --
893: string(6) "double"
894: bool(true)
895: int(-100000)
896: string(7) "integer"
897: -- Iteration 60 --
898: string(6) "double"
899: bool(true)
900: int(100000)
901: string(7) "integer"
902: -- Iteration 61 --
903: string(6) "double"
904: bool(true)
905: int(-100000)
906: string(7) "integer"
907: -- Iteration 62 --
908: string(6) "double"
909: bool(true)
910: int(-1)
911: string(7) "integer"
912: -- Iteration 63 --
913: string(6) "double"
914: bool(true)
915: int(0)
916: string(7) "integer"
917: -- Iteration 64 --
918: string(6) "double"
919: bool(true)
920: int(0)
921: string(7) "integer"
922: -- Iteration 65 --
923: string(6) "double"
924: bool(true)
925: int(500000)
926: string(7) "integer"
927: -- Iteration 66 --
928: string(6) "double"
929: bool(true)
930: int(-500000)
931: string(7) "integer"
932: -- Iteration 67 --
933: string(6) "double"
934: bool(true)
935: int(0)
936: string(7) "integer"
937: -- Iteration 68 --
938: string(6) "double"
939: bool(true)
940: int(500000)
941: string(7) "integer"
942: -- Iteration 69 --
943: string(6) "double"
944: bool(true)
945: int(-500000)
946: string(7) "integer"
947: -- Iteration 70 --
948: string(6) "double"
949: bool(true)
950: int(512000)
951: string(7) "integer"
952: -- Iteration 71 --
953: string(6) "double"
954: bool(true)
955: int(-512000)
956: string(7) "integer"
957: -- Iteration 72 --
958: string(6) "double"
959: bool(true)
960: int(0)
961: string(7) "integer"
962: -- Iteration 73 --
963: string(6) "double"
964: bool(true)
965: int(0)
966: string(7) "integer"
967: -- Iteration 74 --
968: string(6) "double"
969: bool(true)
970: int(512000)
971: string(7) "integer"
972: -- Iteration 75 --
973: string(6) "double"
974: bool(true)
975: int(-512000)
976: string(7) "integer"
977: -- Iteration 76 --
978: string(6) "object"
979: 8: Object of class point could not be converted to int
980: bool(true)
981: int(1)
982: string(7) "integer"
983: -- Iteration 77 --
984: string(6) "object"
985: 8: Object of class point could not be converted to int
986: bool(true)
987: int(1)
988: string(7) "integer"
989: -- Iteration 78 --
990: string(6) "object"
991: 8: Object of class point could not be converted to int
992: bool(true)
993: int(1)
994: string(7) "integer"
995: -- Iteration 79 --
996: string(4) "NULL"
997: bool(true)
998: int(0)
999: string(7) "integer"
1000: -- Iteration 80 --
1001: string(4) "NULL"
1002: bool(true)
1003: int(0)
1004: string(7) "integer"
1005: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>