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}
10?>
11--FILE--
12<?php
13setlocale(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
19echo "*** 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                -0x7fffffff - 1, // max negative integer as hexadecimal
34                '0x7fffffff',  // max positive integer as hexadecimal
35                0x7FFFFFFF,  // max positive integer as hexadecimal
36                '0123',        // integer as octal
37                01,       // should be quivalent to octal 1
38                -017777777777 - 1, // 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() */
43echo "\n*** Output for integer values ***\n";
44foreach($valid_ints as $int_value) {
45echo "\nIteration ".$counter."\n";
46var_export( $int_value );
47echo "\n";
48var_export( $int_value, FALSE);
49echo "\n";
50var_dump( var_export( $int_value, TRUE) );
51echo "\n";
52$counter++;
53}
54
55echo "*** 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() */
67echo "\n*** Output for boolean values ***\n";
68foreach($valid_bool as $bool_value) {
69echo "\nIteration ".$counter."\n";
70var_export( $bool_value );
71echo "\n";
72var_export( $bool_value, FALSE);
73echo "\n";
74var_dump( var_export( $bool_value, TRUE) );
75echo "\n";
76$counter++;
77}
78
79echo "*** Testing var_export() with valid float values ***\n";
80// different valid  float vlaues
81$valid_floats = array(
82  (float)-2147483649, // float value
83  (float)2147483648,  // float value
84  (float)-0x80000001, // float value, beyond max negative int
85  (float)0x800000001, // float value, beyond max positive int
86  (float)020000000001, // float value, beyond max positive int
87  (float)-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() */
105echo "\n*** Output for float values ***\n";
106foreach($valid_floats as $float_value) {
107echo "\nIteration ".$counter."\n";
108var_export( $float_value );
109echo "\n";
110var_export( $float_value, FALSE);
111echo "\n";
112var_dump( var_export( $float_value, TRUE) );
113echo "\n";
114$counter++;
115}
116
117echo "*** 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() */
138echo "\n*** Output for strings ***\n";
139foreach($valid_strings as $str) {
140echo "\nIteration ".$counter."\n";
141var_export( $str );
142echo "\n";
143var_export( $str, FALSE);
144echo "\n";
145var_dump( var_export( $str, TRUE) );
146echo "\n";
147$counter++;
148}
149
150echo "*** 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() */
171echo "\n*** Output for arrays ***\n";
172foreach($valid_arrays as $arr) {
173echo "\nIteration ".$counter."\n";
174var_export( $arr );
175echo "\n";
176var_export( $arr, FALSE);
177echo "\n";
178var_dump( var_export( $arr, TRUE) );
179echo "\n";
180$counter++;
181}
182
183echo "*** Testing var_export() with valid objects ***\n";
184
185// class with no members
186class foo
187{
188// no members
189}
190
191// abstract class
192abstract class abstractClass
193{
194  abstract protected function getClassName();
195  public function printClassName () {
196    echo $this->getClassName() . "\n";
197  }
198}
199// implement abstract class
200class concreteClass extends abstractClass
201{
202  protected function getClassName() {
203    return "concreteClass";
204  }
205}
206
207// interface class
208interface iValue
209{
210   public function setVal ($name, $val);
211   public function dumpVal ();
212}
213// implement the interface
214class 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
228class 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 __construct ( ) {
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() */
266echo "\n*** Output for objects ***\n";
267foreach($valid_objects as $obj) {
268echo "\nIteration ".$counter."\n";
269var_export( $obj );
270echo "\n";
271var_export( $obj, FALSE);
272echo "\n";
273var_dump( var_export( $obj, TRUE) );
274echo "\n";
275$counter++;
276}
277
278echo "*** Testing var_export() with valid null values ***\n";
279// different valid  null vlaues
280$unset_var = array();
281unset ($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() */
291echo "\n*** Output for null values ***\n";
292foreach($valid_nulls as $null_value) {
293echo "\nIteration ".$counter."\n";
294var_export( $null_value );
295echo "\n";
296var_export( $null_value, FALSE);
297echo "\n";
298var_dump( var_export( $null_value, true) );
299echo "\n";
300$counter++;
301}
302
303echo "\n*** Testing error conditions ***\n";
304//Zero argument
305var_export( var_export() );
306
307//arguments more than expected
308var_export( var_export(TRUE, FALSE, TRUE) );
309
310echo "\n\nDone";
311
312
313?>
314--EXPECTF--
315*** Testing var_export() with integer values ***
316
317*** Output for integer values ***
318
319Iteration 1
320'0'
321'0'
322string(3) "'0'"
323
324
325Iteration 2
326'1'
327'1'
328string(3) "'1'"
329
330
331Iteration 3
332'-1'
333'-1'
334string(4) "'-1'"
335
336
337Iteration 4
338'-2147483648'
339'-2147483648'
340string(13) "'-2147483648'"
341
342
343Iteration 5
344'-2147483647'
345'-2147483647'
346string(13) "'-2147483647'"
347
348
349Iteration 6
3502147483647
3512147483647
352string(10) "2147483647"
353
354
355Iteration 7
3562147483640
3572147483640
358string(10) "2147483640"
359
360
361Iteration 8
3624667
3634667
364string(4) "4667"
365
366
367Iteration 9
368'0x12ab'
369'0x12ab'
370string(8) "'0x12ab'"
371
372
373Iteration 10
374'0Xfff'
375'0Xfff'
376string(7) "'0Xfff'"
377
378
379Iteration 11
380'0XFA'
381'0XFA'
382string(6) "'0XFA'"
383
384
385Iteration 12
386-2147483648
387-2147483648
388string(11) "-2147483648"
389
390
391Iteration 13
392'0x7fffffff'
393'0x7fffffff'
394string(12) "'0x7fffffff'"
395
396
397Iteration 14
3982147483647
3992147483647
400string(10) "2147483647"
401
402
403Iteration 15
404'0123'
405'0123'
406string(6) "'0123'"
407
408
409Iteration 16
4101
4111
412string(1) "1"
413
414
415Iteration 17
416-2147483648
417-2147483648
418string(11) "-2147483648"
419
420
421Iteration 18
4222147483647
4232147483647
424string(10) "2147483647"
425
426*** Testing var_export() with valid boolean values ***
427
428*** Output for boolean values ***
429
430Iteration 1
4311
4321
433string(1) "1"
434
435
436Iteration 2
437true
438true
439string(4) "true"
440
441
442Iteration 3
443true
444true
445string(4) "true"
446
447
448Iteration 4
4490
4500
451string(1) "0"
452
453
454Iteration 5
455false
456false
457string(5) "false"
458
459
460Iteration 6
461false
462false
463string(5) "false"
464
465*** Testing var_export() with valid float values ***
466
467*** Output for float values ***
468
469Iteration 1
470-2147483649.0
471-2147483649.0
472string(13) "-2147483649.0"
473
474
475Iteration 2
4762147483648.0
4772147483648.0
478string(12) "2147483648.0"
479
480
481Iteration 3
482-2147483649.0
483-2147483649.0
484string(13) "-2147483649.0"
485
486
487Iteration 4
48834359738369.0
48934359738369.0
490string(13) "34359738369.0"
491
492
493Iteration 5
4942147483649.0
4952147483649.0
496string(12) "2147483649.0"
497
498
499Iteration 6
500-2147483649.0
501-2147483649.0
502string(13) "-2147483649.0"
503
504
505Iteration 7
5060.0
5070.0
508string(3) "0.0"
509
510
511Iteration 8
512-0.10000000000000001
513-0.10000000000000001
514string(20) "-0.10000000000000001"
515
516
517Iteration 9
51810.0
51910.0
520string(4) "10.0"
521
522
523Iteration 10
5241050000.0
5251050000.0
526string(9) "1050000.0"
527
528
529Iteration 11
530100000.0
531100000.0
532string(8) "100000.0"
533
534
535Iteration 12
5361.0000000000000001E-5
5371.0000000000000001E-5
538string(21) "1.0000000000000001E-5"
539
540
541Iteration 13
542100000.0
543100000.0
544string(8) "100000.0"
545
546
547Iteration 14
548100000.0
549100000.0
550string(8) "100000.0"
551
552
553Iteration 15
554100000.0
555100000.0
556string(8) "100000.0"
557
558
559Iteration 16
5601.0000000000000001E-5
5611.0000000000000001E-5
562string(21) "1.0000000000000001E-5"
563
564
565Iteration 17
5665000000.0
5675000000.0
568string(9) "5000000.0"
569
570
571Iteration 18
5726.0000000000000006E-20
5736.0000000000000006E-20
574string(22) "6.0000000000000006E-20"
575
576
577Iteration 19
5785.0000000000000001E+42
5795.0000000000000001E+42
580string(22) "5.0000000000000001E+42"
581
582
583Iteration 20
5843.4000000000000001E-33
5853.4000000000000001E-33
586string(22) "3.4000000000000001E-33"
587
588*** Testing var_export() with valid strings ***
589
590*** Output for strings ***
591
592Iteration 1
593''
594''
595string(2) "''"
596
597
598Iteration 2
599' '
600' '
601string(3) "' '"
602
603
604Iteration 3
605''
606''
607string(2) "''"
608
609
610Iteration 4
611' '
612' '
613string(3) "' '"
614
615
616Iteration 5
617'string'
618'string'
619string(8) "'string'"
620
621
622Iteration 6
623'string'
624'string'
625string(8) "'string'"
626
627
628Iteration 7
629'NULL'
630'NULL'
631string(6) "'NULL'"
632
633
634Iteration 8
635'null'
636'null'
637string(6) "'null'"
638
639
640Iteration 9
641'FALSE'
642'FALSE'
643string(7) "'FALSE'"
644
645
646Iteration 10
647'false'
648'false'
649string(7) "'false'"
650
651
652Iteration 11
653''
654''
655string(3) "''"
656
657
658Iteration 12
659'' . "\0" . ''
660'' . "\0" . ''
661string(14) "'' . "\0" . ''"
662
663
664Iteration 13
665'\\0'
666'\\0'
667string(5) "'\\0'"
668
669
670Iteration 14
671'\\060'
672'\\060'
673string(7) "'\\060'"
674
675
676Iteration 15
677'8'
678'8'
679string(3) "'8'"
680
681*** Testing var_export() with valid arrays ***
682
683*** Output for arrays ***
684
685Iteration 1
686array (
687)
688array (
689)
690string(9) "array (
691)"
692
693
694Iteration 2
695array (
696  0 => NULL,
697)
698array (
699  0 => NULL,
700)
701string(22) "array (
702  0 => NULL,
703)"
704
705
706Iteration 3
707array (
708  0 => NULL,
709)
710array (
711  0 => NULL,
712)
713string(22) "array (
714  0 => NULL,
715)"
716
717
718Iteration 4
719array (
720  0 => true,
721)
722array (
723  0 => true,
724)
725string(22) "array (
726  0 => true,
727)"
728
729
730Iteration 5
731array (
732  0 => '',
733)
734array (
735  0 => '',
736)
737string(20) "array (
738  0 => '',
739)"
740
741
742Iteration 6
743array (
744  0 => '',
745)
746array (
747  0 => '',
748)
749string(20) "array (
750  0 => '',
751)"
752
753
754Iteration 7
755array (
756  0 =>
757  array (
758  ),
759  1 =>
760  array (
761  ),
762)
763array (
764  0 =>
765  array (
766  ),
767  1 =>
768  array (
769  ),
770)
771string(55) "array (
772  0 =>
773  array (
774  ),
775  1 =>
776  array (
777  ),
778)"
779
780
781Iteration 8
782array (
783  0 =>
784  array (
785    0 => 1,
786    1 => 2,
787  ),
788  1 =>
789  array (
790    0 => 'a',
791    1 => 'b',
792  ),
793)
794array (
795  0 =>
796  array (
797    0 => 1,
798    1 => 2,
799  ),
800  1 =>
801  array (
802    0 => 'a',
803    1 => 'b',
804  ),
805)
806string(107) "array (
807  0 =>
808  array (
809    0 => 1,
810    1 => 2,
811  ),
812  1 =>
813  array (
814    0 => 'a',
815    1 => 'b',
816  ),
817)"
818
819
820Iteration 9
821array (
822  1 => 'One',
823)
824array (
825  1 => 'One',
826)
827string(23) "array (
828  1 => 'One',
829)"
830
831
832Iteration 10
833array (
834  'test' => 'is_array',
835)
836array (
837  'test' => 'is_array',
838)
839string(33) "array (
840  'test' => 'is_array',
841)"
842
843
844Iteration 11
845array (
846  0 => 0,
847)
848array (
849  0 => 0,
850)
851string(19) "array (
852  0 => 0,
853)"
854
855
856Iteration 12
857array (
858  0 => -1,
859)
860array (
861  0 => -1,
862)
863string(20) "array (
864  0 => -1,
865)"
866
867
868Iteration 13
869array (
870  0 => 10.5,
871  1 => 5.5999999999999996,
872)
873array (
874  0 => 10.5,
875  1 => 5.5999999999999996,
876)
877string(49) "array (
878  0 => 10.5,
879  1 => 5.5999999999999996,
880)"
881
882
883Iteration 14
884array (
885  0 => 'string',
886  1 => 'test',
887)
888array (
889  0 => 'string',
890  1 => 'test',
891)
892string(41) "array (
893  0 => 'string',
894  1 => 'test',
895)"
896
897
898Iteration 15
899array (
900  0 => 'string',
901  1 => 'test',
902)
903array (
904  0 => 'string',
905  1 => 'test',
906)
907string(41) "array (
908  0 => 'string',
909  1 => 'test',
910)"
911
912*** Testing var_export() with valid objects ***
913
914*** Output for objects ***
915
916Iteration 1
917stdClass::__set_state(array(
918))
919stdClass::__set_state(array(
920))
921string(31) "stdClass::__set_state(array(
922))"
923
924
925Iteration 2
926foo::__set_state(array(
927))
928foo::__set_state(array(
929))
930string(26) "foo::__set_state(array(
931))"
932
933
934Iteration 3
935concreteClass::__set_state(array(
936))
937concreteClass::__set_state(array(
938))
939string(36) "concreteClass::__set_state(array(
940))"
941
942
943Iteration 4
944Value::__set_state(array(
945   'vars' =>
946  array (
947  ),
948))
949Value::__set_state(array(
950   'vars' =>
951  array (
952  ),
953))
954string(57) "Value::__set_state(array(
955   'vars' =>
956  array (
957  ),
958))"
959
960
961Iteration 5
962myClass::__set_state(array(
963   'foo_object' =>
964  foo::__set_state(array(
965  )),
966   'public_var' => 10,
967   'public_var1' =>
968  foo::__set_state(array(
969  )),
970   'private_var' =>
971  foo::__set_state(array(
972  )),
973   'protected_var' => NULL,
974   'proected_var' =>
975  foo::__set_state(array(
976  )),
977))
978myClass::__set_state(array(
979   'foo_object' =>
980  foo::__set_state(array(
981  )),
982   'public_var' => 10,
983   'public_var1' =>
984  foo::__set_state(array(
985  )),
986   'private_var' =>
987  foo::__set_state(array(
988  )),
989   'protected_var' => NULL,
990   'proected_var' =>
991  foo::__set_state(array(
992  )),
993))
994string(293) "myClass::__set_state(array(
995   'foo_object' =>
996  foo::__set_state(array(
997  )),
998   'public_var' => 10,
999   'public_var1' =>
1000  foo::__set_state(array(
1001  )),
1002   'private_var' =>
1003  foo::__set_state(array(
1004  )),
1005   'protected_var' => NULL,
1006   'proected_var' =>
1007  foo::__set_state(array(
1008  )),
1009))"
1010
1011
1012Iteration 6
1013myClass::__set_state(array(
1014   'foo_object' =>
1015  foo::__set_state(array(
1016  )),
1017   'public_var' => 10,
1018   'public_var1' =>
1019  foo::__set_state(array(
1020  )),
1021   'private_var' =>
1022  foo::__set_state(array(
1023  )),
1024   'protected_var' => NULL,
1025   'proected_var' =>
1026  foo::__set_state(array(
1027  )),
1028))
1029myClass::__set_state(array(
1030   'foo_object' =>
1031  foo::__set_state(array(
1032  )),
1033   'public_var' => 10,
1034   'public_var1' =>
1035  foo::__set_state(array(
1036  )),
1037   'private_var' =>
1038  foo::__set_state(array(
1039  )),
1040   'protected_var' => NULL,
1041   'proected_var' =>
1042  foo::__set_state(array(
1043  )),
1044))
1045string(293) "myClass::__set_state(array(
1046   'foo_object' =>
1047  foo::__set_state(array(
1048  )),
1049   'public_var' => 10,
1050   'public_var1' =>
1051  foo::__set_state(array(
1052  )),
1053   'private_var' =>
1054  foo::__set_state(array(
1055  )),
1056   'protected_var' => NULL,
1057   'proected_var' =>
1058  foo::__set_state(array(
1059  )),
1060))"
1061
1062
1063Iteration 7
1064foo::__set_state(array(
1065))
1066foo::__set_state(array(
1067))
1068string(26) "foo::__set_state(array(
1069))"
1070
1071
1072Iteration 8
1073foo::__set_state(array(
1074))
1075foo::__set_state(array(
1076))
1077string(26) "foo::__set_state(array(
1078))"
1079
1080
1081Iteration 9
1082foo::__set_state(array(
1083))
1084foo::__set_state(array(
1085))
1086string(26) "foo::__set_state(array(
1087))"
1088
1089
1090Iteration 10
1091Value::__set_state(array(
1092   'vars' =>
1093  array (
1094  ),
1095))
1096Value::__set_state(array(
1097   'vars' =>
1098  array (
1099  ),
1100))
1101string(57) "Value::__set_state(array(
1102   'vars' =>
1103  array (
1104  ),
1105))"
1106
1107
1108Iteration 11
1109concreteClass::__set_state(array(
1110))
1111concreteClass::__set_state(array(
1112))
1113string(36) "concreteClass::__set_state(array(
1114))"
1115
1116*** Testing var_export() with valid null values ***
1117
1118*** Output for null values ***
1119
1120Iteration 1
1121NULL
1122NULL
1123string(4) "NULL"
1124
1125
1126Iteration 2
1127NULL
1128NULL
1129string(4) "NULL"
1130
1131
1132Iteration 3
1133NULL
1134NULL
1135string(4) "NULL"
1136
1137
1138*** Testing error conditions ***
1139
1140Warning: var_export() expects at least 1 parameter, 0 given in %s on line %d
1141NULL
1142Warning: var_export() expects at most 2 parameters, 3 given in %s on line %d
1143NULL
1144
1145Done
1146