Annotation of embedaddon/php/ext/standard/tests/general_functions/var_export-locale.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test var_export() function with locale
3: --INI--
1.1.1.2 ! misho 4: serialize_precision=17
1.1 misho 5: --SKIPIF--
6: <?php
7: if (!setlocale(LC_ALL, "german", "de","de_DE","de_DE.ISO8859-1","de_DE.ISO_8859-1","de_DE.UTF-8")) {
8: die("skip locale needed for this test is not supported on this platform");
9: }
10: ?>
11: --FILE--
12: <?php
13: setlocale(LC_ALL, "german", "de","de_DE","de_DE.ISO8859-1","de_DE.ISO_8859-1","de_DE.UTF-8");
14: /* Prototype: mixed var_export( mixed expression [, bool return]);
15: * Description: Returns the variable representation when the return parameter is used and evaluates to TRUE. Otherwise, this function will return NULL.
16:
17: */
18:
19: echo "*** Testing var_export() with integer values ***\n";
20: // different integer vlaues
21: $valid_ints = array(
22: '0',
23: '1',
24: '-1',
25: '-2147483648', // max negative integer value
26: '-2147483647',
27: 2147483647, // max positive integer value
28: 2147483640,
29: 0x123B, // integer as hexadecimal
30: '0x12ab',
31: '0Xfff',
32: '0XFA',
33: -0x80000000, // max negative integer as hexadecimal
34: '0x7fffffff', // max postive integer as hexadecimal
35: 0x7FFFFFFF, // max postive integer as hexadecimal
36: '0123', // integer as octal
37: 01912, // should be quivalent to octal 1
38: -020000000000, // max negative integer as octal
39: 017777777777, // max positive integer as octal
40: );
41: $counter = 1;
42: /* Loop to check for above integer values with var_export() */
43: echo "\n*** Output for integer values ***\n";
44: foreach($valid_ints as $int_value) {
45: echo "\nIteration ".$counter."\n";
46: var_export( $int_value );
47: echo "\n";
48: var_export( $int_value, FALSE);
49: echo "\n";
50: var_dump( var_export( $int_value, TRUE) );
51: echo "\n";
52: $counter++;
53: }
54:
55: echo "*** Testing var_export() with valid boolean values ***\n";
56: // different valid boolean vlaues
57: $valid_bool = array(
58: 1,
59: TRUE,
60: true,
61: 0,
62: FALSE,
63: false
64: );
65: $counter = 1;
66: /* Loop to check for above boolean values with var_export() */
67: echo "\n*** Output for boolean values ***\n";
68: foreach($valid_bool as $bool_value) {
69: echo "\nIteration ".$counter."\n";
70: var_export( $bool_value );
71: echo "\n";
72: var_export( $bool_value, FALSE);
73: echo "\n";
74: var_dump( var_export( $bool_value, TRUE) );
75: echo "\n";
76: $counter++;
77: }
78:
79: echo "*** Testing var_export() with valid float values ***\n";
80: // different valid float vlaues
81: $valid_floats = array(
82: -2147483649, // float value
83: 2147483648, // float value
84: -0x80000001, // float value, beyond max negative int
85: 0x800000001, // float value, beyond max positive int
86: 020000000001, // float value, beyond max positive int
87: -020000000001, // float value, beyond max negative int
88: 0.0,
89: -0.1,
90: 10.0000000000000000005,
91: 10.5e+5,
92: 1e5,
93: 1e-5,
94: 1e+5,
95: 1E5,
96: 1E+5,
97: 1E-5,
98: .5e+7,
99: .6e-19,
100: .05E+44,
101: .0034E-30
102: );
103: $counter = 1;
104: /* Loop to check for above float values with var_export() */
105: echo "\n*** Output for float values ***\n";
106: foreach($valid_bool as $float_value) {
107: echo "\nIteration ".$counter."\n";
108: var_export( $float_value );
109: echo "\n";
110: var_export( $float_value, FALSE);
111: echo "\n";
112: var_dump( var_export( $float_value, TRUE) );
113: echo "\n";
114: $counter++;
115: }
116:
117: echo "*** Testing var_export() with valid strings ***\n";
118: // different valid string
119: $valid_strings = array(
120: "",
121: " ",
122: '',
123: ' ',
124: "string",
125: 'string',
126: "NULL",
127: 'null',
128: "FALSE",
129: 'false',
130: "\x0b",
131: "\0",
132: '\0',
133: '\060',
134: "\070"
135: );
136: $counter = 1;
137: /* Loop to check for above strings with var_export() */
138: echo "\n*** Output for strings ***\n";
139: foreach($valid_strings as $str) {
140: echo "\nIteration ".$counter."\n";
141: var_export( $str );
142: echo "\n";
143: var_export( $str, FALSE);
144: echo "\n";
145: var_dump( var_export( $str, TRUE) );
146: echo "\n";
147: $counter++;
148: }
149:
150: echo "*** Testing var_export() with valid arrays ***\n";
151: // different valid arrays
152: $valid_arrays = array(
153: array(),
154: array(NULL),
155: array(null),
156: array(true),
157: array(""),
158: array(''),
159: array(array(), array()),
160: array(array(1, 2), array('a', 'b')),
161: array(1 => 'One'),
162: array("test" => "is_array"),
163: array(0),
164: array(-1),
165: array(10.5, 5.6),
166: array("string", "test"),
167: array('string', 'test')
168: );
169: $counter = 1;
170: /* Loop to check for above arrays with var_export() */
171: echo "\n*** Output for arrays ***\n";
172: foreach($valid_arrays as $arr) {
173: echo "\nIteration ".$counter."\n";
174: var_export( $arr );
175: echo "\n";
176: var_export( $arr, FALSE);
177: echo "\n";
178: var_dump( var_export( $arr, TRUE) );
179: echo "\n";
180: $counter++;
181: }
182:
183: echo "*** Testing var_export() with valid objects ***\n";
184:
185: // class with no members
186: class foo
187: {
188: // no members
189: }
190:
191: // abstract class
192: abstract class abstractClass
193: {
194: abstract protected function getClassName();
195: public function printClassName () {
196: echo $this->getClassName() . "\n";
197: }
198: }
199: // implement abstract class
200: class concreteClass extends abstractClass
201: {
202: protected function getClassName() {
203: return "concreteClass";
204: }
205: }
206:
207: // interface class
208: interface iValue
209: {
210: public function setVal ($name, $val);
211: public function dumpVal ();
212: }
213: // implement the interface
214: class Value implements iValue
215: {
216: private $vars = array ();
217:
218: public function setVal ( $name, $val ) {
219: $this->vars[$name] = $val;
220: }
221:
222: public function dumpVal () {
223: var_export ( $vars );
224: }
225: }
226:
227: // a gereral class
228: class myClass
229: {
230: var $foo_object;
231: public $public_var;
232: public $public_var1;
233: private $private_var;
234: protected $protected_var;
235:
236: function myClass ( ) {
237: $this->foo_object = new foo();
238: $this->public_var = 10;
239: $this->public_var1 = new foo();
240: $this->private_var = new foo();
241: $this->proected_var = new foo();
242: }
243: }
244:
245: // create a object of each class defined above
246: $myClass_object = new myClass();
247: $foo_object = new foo();
248: $Value_object = new Value();
249: $concreteClass_object = new concreteClass();
250:
251: $valid_objects = array(
252: new stdclass,
253: new foo,
254: new concreteClass,
255: new Value,
256: new myClass,
257: $myClass_object,
258: $myClass_object->foo_object,
259: $myClass_object->public_var1,
260: $foo_object,
261: $Value_object,
262: $concreteClass_object
263: );
264: $counter = 1;
265: /* Loop to check for above objects with var_export() */
266: echo "\n*** Output for objects ***\n";
267: foreach($valid_objects as $obj) {
268: echo "\nIteration ".$counter."\n";
269: var_export( $obj );
270: echo "\n";
271: var_export( $obj, FALSE);
272: echo "\n";
273: var_dump( var_export( $obj, TRUE) );
274: echo "\n";
275: $counter++;
276: }
277:
278: echo "*** Testing var_export() with valid null values ***\n";
279: // different valid null vlaues
280: $unset_var = array();
281: unset ($unset_var); // now a null
282: $null_var = NULL;
283:
284: $valid_nulls = array(
285: NULL,
286: null,
287: $null_var,
288: );
289: $counter = 1;
290: /* Loop to check for above null values with var_export() */
291: echo "\n*** Output for null values ***\n";
292: foreach($valid_nulls as $null_value) {
293: echo "\nIteration ".$counter."\n";
294: var_export( $null_value );
295: echo "\n";
296: var_export( $null_value, FALSE);
297: echo "\n";
298: var_dump( var_export( $null_value, true) );
299: echo "\n";
300: $counter++;
301: }
302:
303: echo "\n*** Testing error conditions ***\n";
304: //Zero argument
305: var_export( var_export() );
306:
307: //arguments more than expected
308: var_export( var_export(TRUE, FALSE, TRUE) );
309:
310: echo "\n\nDone";
311:
312:
313: ?>
314: --EXPECTF--
315: *** Testing var_export() with integer values ***
316:
317: *** Output for integer values ***
318:
319: Iteration 1
320: '0'
321: '0'
322: string(3) "'0'"
323:
324:
325: Iteration 2
326: '1'
327: '1'
328: string(3) "'1'"
329:
330:
331: Iteration 3
332: '-1'
333: '-1'
334: string(4) "'-1'"
335:
336:
337: Iteration 4
338: '-2147483648'
339: '-2147483648'
340: string(13) "'-2147483648'"
341:
342:
343: Iteration 5
344: '-2147483647'
345: '-2147483647'
346: string(13) "'-2147483647'"
347:
348:
349: Iteration 6
350: 2147483647
351: 2147483647
352: string(10) "2147483647"
353:
354:
355: Iteration 7
356: 2147483640
357: 2147483640
358: string(10) "2147483640"
359:
360:
361: Iteration 8
362: 4667
363: 4667
364: string(4) "4667"
365:
366:
367: Iteration 9
368: '0x12ab'
369: '0x12ab'
370: string(8) "'0x12ab'"
371:
372:
373: Iteration 10
374: '0Xfff'
375: '0Xfff'
376: string(7) "'0Xfff'"
377:
378:
379: Iteration 11
380: '0XFA'
381: '0XFA'
382: string(6) "'0XFA'"
383:
384:
385: Iteration 12
386: -2147483648
387: -2147483648
388: string(11) "-2147483648"
389:
390:
391: Iteration 13
392: '0x7fffffff'
393: '0x7fffffff'
394: string(12) "'0x7fffffff'"
395:
396:
397: Iteration 14
398: 2147483647
399: 2147483647
400: string(10) "2147483647"
401:
402:
403: Iteration 15
404: '0123'
405: '0123'
406: string(6) "'0123'"
407:
408:
409: Iteration 16
410: 1
411: 1
412: string(1) "1"
413:
414:
415: Iteration 17
416: -2147483648
417: -2147483648
418: string(11) "-2147483648"
419:
420:
421: Iteration 18
422: 2147483647
423: 2147483647
424: string(10) "2147483647"
425:
426: *** Testing var_export() with valid boolean values ***
427:
428: *** Output for boolean values ***
429:
430: Iteration 1
431: 1
432: 1
433: string(1) "1"
434:
435:
436: Iteration 2
437: true
438: true
439: string(4) "true"
440:
441:
442: Iteration 3
443: true
444: true
445: string(4) "true"
446:
447:
448: Iteration 4
449: 0
450: 0
451: string(1) "0"
452:
453:
454: Iteration 5
455: false
456: false
457: string(5) "false"
458:
459:
460: Iteration 6
461: false
462: false
463: string(5) "false"
464:
465: *** Testing var_export() with valid float values ***
466:
467: *** Output for float values ***
468:
469: Iteration 1
470: 1
471: 1
472: string(1) "1"
473:
474:
475: Iteration 2
476: true
477: true
478: string(4) "true"
479:
480:
481: Iteration 3
482: true
483: true
484: string(4) "true"
485:
486:
487: Iteration 4
488: 0
489: 0
490: string(1) "0"
491:
492:
493: Iteration 5
494: false
495: false
496: string(5) "false"
497:
498:
499: Iteration 6
500: false
501: false
502: string(5) "false"
503:
504: *** Testing var_export() with valid strings ***
505:
506: *** Output for strings ***
507:
508: Iteration 1
509: ''
510: ''
511: string(2) "''"
512:
513:
514: Iteration 2
515: ' '
516: ' '
517: string(3) "' '"
518:
519:
520: Iteration 3
521: ''
522: ''
523: string(2) "''"
524:
525:
526: Iteration 4
527: ' '
528: ' '
529: string(3) "' '"
530:
531:
532: Iteration 5
533: 'string'
534: 'string'
535: string(8) "'string'"
536:
537:
538: Iteration 6
539: 'string'
540: 'string'
541: string(8) "'string'"
542:
543:
544: Iteration 7
545: 'NULL'
546: 'NULL'
547: string(6) "'NULL'"
548:
549:
550: Iteration 8
551: 'null'
552: 'null'
553: string(6) "'null'"
554:
555:
556: Iteration 9
557: 'FALSE'
558: 'FALSE'
559: string(7) "'FALSE'"
560:
561:
562: Iteration 10
563: 'false'
564: 'false'
565: string(7) "'false'"
566:
567:
568: Iteration 11
569: ''
570: ''
571: string(3) "''"
572:
573:
574: Iteration 12
575: '' . "\0" . ''
576: '' . "\0" . ''
577: string(14) "'' . "\0" . ''"
578:
579:
580: Iteration 13
581: '\\0'
582: '\\0'
583: string(5) "'\\0'"
584:
585:
586: Iteration 14
587: '\\060'
588: '\\060'
589: string(7) "'\\060'"
590:
591:
592: Iteration 15
593: '8'
594: '8'
595: string(3) "'8'"
596:
597: *** Testing var_export() with valid arrays ***
598:
599: *** Output for arrays ***
600:
601: Iteration 1
602: array (
603: )
604: array (
605: )
606: string(9) "array (
607: )"
608:
609:
610: Iteration 2
611: array (
612: 0 => NULL,
613: )
614: array (
615: 0 => NULL,
616: )
617: string(22) "array (
618: 0 => NULL,
619: )"
620:
621:
622: Iteration 3
623: array (
624: 0 => NULL,
625: )
626: array (
627: 0 => NULL,
628: )
629: string(22) "array (
630: 0 => NULL,
631: )"
632:
633:
634: Iteration 4
635: array (
636: 0 => true,
637: )
638: array (
639: 0 => true,
640: )
641: string(22) "array (
642: 0 => true,
643: )"
644:
645:
646: Iteration 5
647: array (
648: 0 => '',
649: )
650: array (
651: 0 => '',
652: )
653: string(20) "array (
654: 0 => '',
655: )"
656:
657:
658: Iteration 6
659: array (
660: 0 => '',
661: )
662: array (
663: 0 => '',
664: )
665: string(20) "array (
666: 0 => '',
667: )"
668:
669:
670: Iteration 7
671: array (
672: 0 =>
673: array (
674: ),
675: 1 =>
676: array (
677: ),
678: )
679: array (
680: 0 =>
681: array (
682: ),
683: 1 =>
684: array (
685: ),
686: )
687: string(55) "array (
688: 0 =>
689: array (
690: ),
691: 1 =>
692: array (
693: ),
694: )"
695:
696:
697: Iteration 8
698: array (
699: 0 =>
700: array (
701: 0 => 1,
702: 1 => 2,
703: ),
704: 1 =>
705: array (
706: 0 => 'a',
707: 1 => 'b',
708: ),
709: )
710: array (
711: 0 =>
712: array (
713: 0 => 1,
714: 1 => 2,
715: ),
716: 1 =>
717: array (
718: 0 => 'a',
719: 1 => 'b',
720: ),
721: )
722: string(107) "array (
723: 0 =>
724: array (
725: 0 => 1,
726: 1 => 2,
727: ),
728: 1 =>
729: array (
730: 0 => 'a',
731: 1 => 'b',
732: ),
733: )"
734:
735:
736: Iteration 9
737: array (
738: 1 => 'One',
739: )
740: array (
741: 1 => 'One',
742: )
743: string(23) "array (
744: 1 => 'One',
745: )"
746:
747:
748: Iteration 10
749: array (
750: 'test' => 'is_array',
751: )
752: array (
753: 'test' => 'is_array',
754: )
755: string(33) "array (
756: 'test' => 'is_array',
757: )"
758:
759:
760: Iteration 11
761: array (
762: 0 => 0,
763: )
764: array (
765: 0 => 0,
766: )
767: string(19) "array (
768: 0 => 0,
769: )"
770:
771:
772: Iteration 12
773: array (
774: 0 => -1,
775: )
776: array (
777: 0 => -1,
778: )
779: string(20) "array (
780: 0 => -1,
781: )"
782:
783:
784: Iteration 13
785: array (
786: 0 => 10.5,
1.1.1.2 ! misho 787: 1 => 5.5999999999999996,
1.1 misho 788: )
789: array (
790: 0 => 10.5,
1.1.1.2 ! misho 791: 1 => 5.5999999999999996,
1.1 misho 792: )
1.1.1.2 ! misho 793: string(49) "array (
1.1 misho 794: 0 => 10.5,
1.1.1.2 ! misho 795: 1 => 5.5999999999999996,
1.1 misho 796: )"
797:
798:
799: Iteration 14
800: array (
801: 0 => 'string',
802: 1 => 'test',
803: )
804: array (
805: 0 => 'string',
806: 1 => 'test',
807: )
808: string(41) "array (
809: 0 => 'string',
810: 1 => 'test',
811: )"
812:
813:
814: Iteration 15
815: array (
816: 0 => 'string',
817: 1 => 'test',
818: )
819: array (
820: 0 => 'string',
821: 1 => 'test',
822: )
823: string(41) "array (
824: 0 => 'string',
825: 1 => 'test',
826: )"
827:
828: *** Testing var_export() with valid objects ***
829:
830: *** Output for objects ***
831:
832: Iteration 1
833: stdClass::__set_state(array(
834: ))
835: stdClass::__set_state(array(
836: ))
837: string(31) "stdClass::__set_state(array(
838: ))"
839:
840:
841: Iteration 2
842: foo::__set_state(array(
843: ))
844: foo::__set_state(array(
845: ))
846: string(26) "foo::__set_state(array(
847: ))"
848:
849:
850: Iteration 3
851: concreteClass::__set_state(array(
852: ))
853: concreteClass::__set_state(array(
854: ))
855: string(36) "concreteClass::__set_state(array(
856: ))"
857:
858:
859: Iteration 4
860: Value::__set_state(array(
861: 'vars' =>
862: array (
863: ),
864: ))
865: Value::__set_state(array(
866: 'vars' =>
867: array (
868: ),
869: ))
870: string(57) "Value::__set_state(array(
871: 'vars' =>
872: array (
873: ),
874: ))"
875:
876:
877: Iteration 5
878: myClass::__set_state(array(
879: 'foo_object' =>
880: foo::__set_state(array(
881: )),
882: 'public_var' => 10,
883: 'public_var1' =>
884: foo::__set_state(array(
885: )),
886: 'private_var' =>
887: foo::__set_state(array(
888: )),
889: 'protected_var' => NULL,
890: 'proected_var' =>
891: foo::__set_state(array(
892: )),
893: ))
894: myClass::__set_state(array(
895: 'foo_object' =>
896: foo::__set_state(array(
897: )),
898: 'public_var' => 10,
899: 'public_var1' =>
900: foo::__set_state(array(
901: )),
902: 'private_var' =>
903: foo::__set_state(array(
904: )),
905: 'protected_var' => NULL,
906: 'proected_var' =>
907: foo::__set_state(array(
908: )),
909: ))
910: string(293) "myClass::__set_state(array(
911: 'foo_object' =>
912: foo::__set_state(array(
913: )),
914: 'public_var' => 10,
915: 'public_var1' =>
916: foo::__set_state(array(
917: )),
918: 'private_var' =>
919: foo::__set_state(array(
920: )),
921: 'protected_var' => NULL,
922: 'proected_var' =>
923: foo::__set_state(array(
924: )),
925: ))"
926:
927:
928: Iteration 6
929: myClass::__set_state(array(
930: 'foo_object' =>
931: foo::__set_state(array(
932: )),
933: 'public_var' => 10,
934: 'public_var1' =>
935: foo::__set_state(array(
936: )),
937: 'private_var' =>
938: foo::__set_state(array(
939: )),
940: 'protected_var' => NULL,
941: 'proected_var' =>
942: foo::__set_state(array(
943: )),
944: ))
945: myClass::__set_state(array(
946: 'foo_object' =>
947: foo::__set_state(array(
948: )),
949: 'public_var' => 10,
950: 'public_var1' =>
951: foo::__set_state(array(
952: )),
953: 'private_var' =>
954: foo::__set_state(array(
955: )),
956: 'protected_var' => NULL,
957: 'proected_var' =>
958: foo::__set_state(array(
959: )),
960: ))
961: string(293) "myClass::__set_state(array(
962: 'foo_object' =>
963: foo::__set_state(array(
964: )),
965: 'public_var' => 10,
966: 'public_var1' =>
967: foo::__set_state(array(
968: )),
969: 'private_var' =>
970: foo::__set_state(array(
971: )),
972: 'protected_var' => NULL,
973: 'proected_var' =>
974: foo::__set_state(array(
975: )),
976: ))"
977:
978:
979: Iteration 7
980: foo::__set_state(array(
981: ))
982: foo::__set_state(array(
983: ))
984: string(26) "foo::__set_state(array(
985: ))"
986:
987:
988: Iteration 8
989: foo::__set_state(array(
990: ))
991: foo::__set_state(array(
992: ))
993: string(26) "foo::__set_state(array(
994: ))"
995:
996:
997: Iteration 9
998: foo::__set_state(array(
999: ))
1000: foo::__set_state(array(
1001: ))
1002: string(26) "foo::__set_state(array(
1003: ))"
1004:
1005:
1006: Iteration 10
1007: Value::__set_state(array(
1008: 'vars' =>
1009: array (
1010: ),
1011: ))
1012: Value::__set_state(array(
1013: 'vars' =>
1014: array (
1015: ),
1016: ))
1017: string(57) "Value::__set_state(array(
1018: 'vars' =>
1019: array (
1020: ),
1021: ))"
1022:
1023:
1024: Iteration 11
1025: concreteClass::__set_state(array(
1026: ))
1027: concreteClass::__set_state(array(
1028: ))
1029: string(36) "concreteClass::__set_state(array(
1030: ))"
1031:
1032: *** Testing var_export() with valid null values ***
1033:
1034: *** Output for null values ***
1035:
1036: Iteration 1
1037: NULL
1038: NULL
1039: string(4) "NULL"
1040:
1041:
1042: Iteration 2
1043: NULL
1044: NULL
1045: string(4) "NULL"
1046:
1047:
1048: Iteration 3
1049: NULL
1050: NULL
1051: string(4) "NULL"
1052:
1053:
1054: *** Testing error conditions ***
1055:
1056: Warning: var_export() expects at least 1 parameter, 0 given in %s on line %d
1057: NULL
1058: Warning: var_export() expects at most 2 parameters, 3 given in %s on line %d
1059: NULL
1060:
1061: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>