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