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