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