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