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 < 8) {
11        die("skip 64-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");
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
22echo "*** 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() */
46echo "\n*** Output for integer values ***\n";
47foreach($valid_ints as $int_value) {
48echo "\nIteration ".$counter."\n";
49var_export( $int_value );
50echo "\n";
51var_export( $int_value, FALSE);
52echo "\n";
53var_dump( var_export( $int_value, TRUE) );
54echo "\n";
55$counter++;
56}
57
58echo "*** 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() */
70echo "\n*** Output for boolean values ***\n";
71foreach($valid_bool as $bool_value) {
72echo "\nIteration ".$counter."\n";
73var_export( $bool_value );
74echo "\n";
75var_export( $bool_value, FALSE);
76echo "\n";
77var_dump( var_export( $bool_value, TRUE) );
78echo "\n";
79$counter++;
80}
81
82echo "*** 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() */
108echo "\n*** Output for float values ***\n";
109foreach($valid_floats as $float_value) {
110echo "\nIteration ".$counter."\n";
111var_export( $float_value );
112echo "\n";
113var_export( $float_value, FALSE);
114echo "\n";
115var_dump( var_export( $float_value, TRUE) );
116echo "\n";
117$counter++;
118}
119
120echo "*** 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() */
141echo "\n*** Output for strings ***\n";
142foreach($valid_strings as $str) {
143echo "\nIteration ".$counter."\n";
144var_export( $str );
145echo "\n";
146var_export( $str, FALSE);
147echo "\n";
148var_dump( var_export( $str, TRUE) );
149echo "\n";
150$counter++;
151}
152
153echo "*** 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() */
174echo "\n*** Output for arrays ***\n";
175foreach($valid_arrays as $arr) {
176echo "\nIteration ".$counter."\n";
177var_export( $arr );
178echo "\n";
179var_export( $arr, FALSE);
180echo "\n";
181var_dump( var_export( $arr, TRUE) );
182echo "\n";
183$counter++;
184}
185
186echo "*** Testing var_export() with valid objects ***\n";
187
188// class with no members
189class foo
190{
191// no members
192}
193
194// abstract class
195abstract class abstractClass
196{
197  abstract protected function getClassName();
198  public function printClassName () {
199    echo $this->getClassName() . "\n";
200  }
201}
202// implement abstract class
203class concreteClass extends abstractClass
204{
205  protected function getClassName() {
206    return "concreteClass";
207  }
208}
209
210// interface class
211interface iValue
212{
213   public function setVal ($name, $val);
214   public function dumpVal ();
215}
216// implement the interface
217class 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
231class 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() */
269echo "\n*** Output for objects ***\n";
270foreach($valid_objects as $obj) {
271echo "\nIteration ".$counter."\n";
272var_export( $obj );
273echo "\n";
274var_export( $obj, FALSE);
275echo "\n";
276var_dump( var_export( $obj, TRUE) );
277echo "\n";
278$counter++;
279}
280
281echo "*** Testing var_export() with valid null values ***\n";
282// different valid  null values
283$unset_var = array();
284unset ($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() */
294echo "\n*** Output for null values ***\n";
295foreach($valid_nulls as $null_value) {
296echo "\nIteration ".$counter."\n";
297var_export( $null_value );
298echo "\n";
299var_export( $null_value, FALSE);
300echo "\n";
301var_dump( var_export( $null_value, true) );
302echo "\n";
303$counter++;
304}
305
306echo "\n*** Testing error conditions ***\n";
307//Zero argument
308var_export( var_export() );
309
310//arguments more than expected
311var_export( var_export(TRUE, FALSE, TRUE) );
312
313echo "\n\nDone";
314
315
316?>
317--EXPECTF--
318*** Testing var_export() with integer values ***
319
320*** Output for integer values ***
321
322Iteration 1
323'0'
324'0'
325string(3) "'0'"
326
327
328Iteration 2
329'1'
330'1'
331string(3) "'1'"
332
333
334Iteration 3
335'-1'
336'-1'
337string(4) "'-1'"
338
339
340Iteration 4
341'-2147483648'
342'-2147483648'
343string(13) "'-2147483648'"
344
345
346Iteration 5
347'-2147483647'
348'-2147483647'
349string(13) "'-2147483647'"
350
351
352Iteration 6
3532147483647
3542147483647
355string(10) "2147483647"
356
357
358Iteration 7
3592147483640
3602147483640
361string(10) "2147483640"
362
363
364Iteration 8
3654667
3664667
367string(4) "4667"
368
369
370Iteration 9
371'0x12ab'
372'0x12ab'
373string(8) "'0x12ab'"
374
375
376Iteration 10
377'0Xfff'
378'0Xfff'
379string(7) "'0Xfff'"
380
381
382Iteration 11
383'0XFA'
384'0XFA'
385string(6) "'0XFA'"
386
387
388Iteration 12
389-2147483648
390-2147483648
391string(11) "-2147483648"
392
393
394Iteration 13
395'0x7fffffff'
396'0x7fffffff'
397string(12) "'0x7fffffff'"
398
399
400Iteration 14
4012147483647
4022147483647
403string(10) "2147483647"
404
405
406Iteration 15
407'0123'
408'0123'
409string(6) "'0123'"
410
411
412Iteration 16
4131
4141
415string(1) "1"
416
417
418Iteration 17
419-2147483648
420-2147483648
421string(11) "-2147483648"
422
423
424Iteration 18
4252147483647
4262147483647
427string(10) "2147483647"
428
429*** Testing var_export() with valid boolean values ***
430
431*** Output for boolean values ***
432
433Iteration 1
4341
4351
436string(1) "1"
437
438
439Iteration 2
440true
441true
442string(4) "true"
443
444
445Iteration 3
446true
447true
448string(4) "true"
449
450
451Iteration 4
4520
4530
454string(1) "0"
455
456
457Iteration 5
458false
459false
460string(5) "false"
461
462
463Iteration 6
464false
465false
466string(5) "false"
467
468*** Testing var_export() with valid float values ***
469
470*** Output for float values ***
471
472Iteration 1
473-2147483649.0
474-2147483649.0
475string(13) "-2147483649.0"
476
477
478Iteration 2
4792147483648.0
4802147483648.0
481string(12) "2147483648.0"
482
483
484Iteration 3
485-2147483649.0
486-2147483649.0
487string(13) "-2147483649.0"
488
489
490Iteration 4
49134359738369.0
49234359738369.0
493string(13) "34359738369.0"
494
495
496Iteration 5
4972147483649.0
4982147483649.0
499string(12) "2147483649.0"
500
501
502Iteration 6
503-2147483649.0
504-2147483649.0
505string(13) "-2147483649.0"
506
507
508Iteration 7
5090.0
5100.0
511string(3) "0.0"
512
513
514Iteration 8
515-0.10000000000000001
516-0.10000000000000001
517string(20) "-0.10000000000000001"
518
519
520Iteration 9
52110.0
52210.0
523string(4) "10.0"
524
525
526Iteration 10
5271050000.0
5281050000.0
529string(9) "1050000.0"
530
531
532Iteration 11
533100000.0
534100000.0
535string(8) "100000.0"
536
537
538Iteration 12
5391.0000000000000001E-5
5401.0000000000000001E-5
541string(21) "1.0000000000000001E-5"
542
543
544Iteration 13
545100000.0
546100000.0
547string(8) "100000.0"
548
549
550Iteration 14
551100000.0
552100000.0
553string(8) "100000.0"
554
555
556Iteration 15
557100000.0
558100000.0
559string(8) "100000.0"
560
561
562Iteration 16
5631.0000000000000001E-5
5641.0000000000000001E-5
565string(21) "1.0000000000000001E-5"
566
567
568Iteration 17
5695000000.0
5705000000.0
571string(9) "5000000.0"
572
573
574Iteration 18
5756.0000000000000006E-20
5766.0000000000000006E-20
577string(22) "6.0000000000000006E-20"
578
579
580Iteration 19
5815.0000000000000001E+42
5825.0000000000000001E+42
583string(22) "5.0000000000000001E+42"
584
585
586Iteration 20
5873.4000000000000001E-33
5883.4000000000000001E-33
589string(22) "3.4000000000000001E-33"
590
591*** Testing var_export() with valid strings ***
592
593*** Output for strings ***
594
595Iteration 1
596''
597''
598string(2) "''"
599
600
601Iteration 2
602' '
603' '
604string(3) "' '"
605
606
607Iteration 3
608''
609''
610string(2) "''"
611
612
613Iteration 4
614' '
615' '
616string(3) "' '"
617
618
619Iteration 5
620'string'
621'string'
622string(8) "'string'"
623
624
625Iteration 6
626'string'
627'string'
628string(8) "'string'"
629
630
631Iteration 7
632'NULL'
633'NULL'
634string(6) "'NULL'"
635
636
637Iteration 8
638'null'
639'null'
640string(6) "'null'"
641
642
643Iteration 9
644'FALSE'
645'FALSE'
646string(7) "'FALSE'"
647
648
649Iteration 10
650'false'
651'false'
652string(7) "'false'"
653
654
655Iteration 11
656''
657''
658string(3) "''"
659
660
661Iteration 12
662'' . "\0" . ''
663'' . "\0" . ''
664string(14) "'' . "\0" . ''"
665
666
667Iteration 13
668'\\0'
669'\\0'
670string(5) "'\\0'"
671
672
673Iteration 14
674'\\060'
675'\\060'
676string(7) "'\\060'"
677
678
679Iteration 15
680'8'
681'8'
682string(3) "'8'"
683
684*** Testing var_export() with valid arrays ***
685
686*** Output for arrays ***
687
688Iteration 1
689array (
690)
691array (
692)
693string(9) "array (
694)"
695
696
697Iteration 2
698array (
699  0 => NULL,
700)
701array (
702  0 => NULL,
703)
704string(22) "array (
705  0 => NULL,
706)"
707
708
709Iteration 3
710array (
711  0 => NULL,
712)
713array (
714  0 => NULL,
715)
716string(22) "array (
717  0 => NULL,
718)"
719
720
721Iteration 4
722array (
723  0 => true,
724)
725array (
726  0 => true,
727)
728string(22) "array (
729  0 => true,
730)"
731
732
733Iteration 5
734array (
735  0 => '',
736)
737array (
738  0 => '',
739)
740string(20) "array (
741  0 => '',
742)"
743
744
745Iteration 6
746array (
747  0 => '',
748)
749array (
750  0 => '',
751)
752string(20) "array (
753  0 => '',
754)"
755
756
757Iteration 7
758array (
759  0 =>
760  array (
761  ),
762  1 =>
763  array (
764  ),
765)
766array (
767  0 =>
768  array (
769  ),
770  1 =>
771  array (
772  ),
773)
774string(55) "array (
775  0 =>
776  array (
777  ),
778  1 =>
779  array (
780  ),
781)"
782
783
784Iteration 8
785array (
786  0 =>
787  array (
788    0 => 1,
789    1 => 2,
790  ),
791  1 =>
792  array (
793    0 => 'a',
794    1 => 'b',
795  ),
796)
797array (
798  0 =>
799  array (
800    0 => 1,
801    1 => 2,
802  ),
803  1 =>
804  array (
805    0 => 'a',
806    1 => 'b',
807  ),
808)
809string(107) "array (
810  0 =>
811  array (
812    0 => 1,
813    1 => 2,
814  ),
815  1 =>
816  array (
817    0 => 'a',
818    1 => 'b',
819  ),
820)"
821
822
823Iteration 9
824array (
825  1 => 'One',
826)
827array (
828  1 => 'One',
829)
830string(23) "array (
831  1 => 'One',
832)"
833
834
835Iteration 10
836array (
837  'test' => 'is_array',
838)
839array (
840  'test' => 'is_array',
841)
842string(33) "array (
843  'test' => 'is_array',
844)"
845
846
847Iteration 11
848array (
849  0 => 0,
850)
851array (
852  0 => 0,
853)
854string(19) "array (
855  0 => 0,
856)"
857
858
859Iteration 12
860array (
861  0 => -1,
862)
863array (
864  0 => -1,
865)
866string(20) "array (
867  0 => -1,
868)"
869
870
871Iteration 13
872array (
873  0 => 10.5,
874  1 => 5.5999999999999996,
875)
876array (
877  0 => 10.5,
878  1 => 5.5999999999999996,
879)
880string(49) "array (
881  0 => 10.5,
882  1 => 5.5999999999999996,
883)"
884
885
886Iteration 14
887array (
888  0 => 'string',
889  1 => 'test',
890)
891array (
892  0 => 'string',
893  1 => 'test',
894)
895string(41) "array (
896  0 => 'string',
897  1 => 'test',
898)"
899
900
901Iteration 15
902array (
903  0 => 'string',
904  1 => 'test',
905)
906array (
907  0 => 'string',
908  1 => 'test',
909)
910string(41) "array (
911  0 => 'string',
912  1 => 'test',
913)"
914
915*** Testing var_export() with valid objects ***
916
917*** Output for objects ***
918
919Iteration 1
920(object) array(
921)
922(object) array(
923)
924string(17) "(object) array(
925)"
926
927
928Iteration 2
929foo::__set_state(array(
930))
931foo::__set_state(array(
932))
933string(26) "foo::__set_state(array(
934))"
935
936
937Iteration 3
938concreteClass::__set_state(array(
939))
940concreteClass::__set_state(array(
941))
942string(36) "concreteClass::__set_state(array(
943))"
944
945
946Iteration 4
947Value::__set_state(array(
948   'vars' =>
949  array (
950  ),
951))
952Value::__set_state(array(
953   'vars' =>
954  array (
955  ),
956))
957string(57) "Value::__set_state(array(
958   'vars' =>
959  array (
960  ),
961))"
962
963
964Iteration 5
965myClass::__set_state(array(
966   'foo_object' =>
967  foo::__set_state(array(
968  )),
969   'public_var' => 10,
970   'public_var1' =>
971  foo::__set_state(array(
972  )),
973   'private_var' =>
974  foo::__set_state(array(
975  )),
976   'protected_var' => NULL,
977   'proected_var' =>
978  foo::__set_state(array(
979  )),
980))
981myClass::__set_state(array(
982   'foo_object' =>
983  foo::__set_state(array(
984  )),
985   'public_var' => 10,
986   'public_var1' =>
987  foo::__set_state(array(
988  )),
989   'private_var' =>
990  foo::__set_state(array(
991  )),
992   'protected_var' => NULL,
993   'proected_var' =>
994  foo::__set_state(array(
995  )),
996))
997string(293) "myClass::__set_state(array(
998   'foo_object' =>
999  foo::__set_state(array(
1000  )),
1001   'public_var' => 10,
1002   'public_var1' =>
1003  foo::__set_state(array(
1004  )),
1005   'private_var' =>
1006  foo::__set_state(array(
1007  )),
1008   'protected_var' => NULL,
1009   'proected_var' =>
1010  foo::__set_state(array(
1011  )),
1012))"
1013
1014
1015Iteration 6
1016myClass::__set_state(array(
1017   'foo_object' =>
1018  foo::__set_state(array(
1019  )),
1020   'public_var' => 10,
1021   'public_var1' =>
1022  foo::__set_state(array(
1023  )),
1024   'private_var' =>
1025  foo::__set_state(array(
1026  )),
1027   'protected_var' => NULL,
1028   'proected_var' =>
1029  foo::__set_state(array(
1030  )),
1031))
1032myClass::__set_state(array(
1033   'foo_object' =>
1034  foo::__set_state(array(
1035  )),
1036   'public_var' => 10,
1037   'public_var1' =>
1038  foo::__set_state(array(
1039  )),
1040   'private_var' =>
1041  foo::__set_state(array(
1042  )),
1043   'protected_var' => NULL,
1044   'proected_var' =>
1045  foo::__set_state(array(
1046  )),
1047))
1048string(293) "myClass::__set_state(array(
1049   'foo_object' =>
1050  foo::__set_state(array(
1051  )),
1052   'public_var' => 10,
1053   'public_var1' =>
1054  foo::__set_state(array(
1055  )),
1056   'private_var' =>
1057  foo::__set_state(array(
1058  )),
1059   'protected_var' => NULL,
1060   'proected_var' =>
1061  foo::__set_state(array(
1062  )),
1063))"
1064
1065
1066Iteration 7
1067foo::__set_state(array(
1068))
1069foo::__set_state(array(
1070))
1071string(26) "foo::__set_state(array(
1072))"
1073
1074
1075Iteration 8
1076foo::__set_state(array(
1077))
1078foo::__set_state(array(
1079))
1080string(26) "foo::__set_state(array(
1081))"
1082
1083
1084Iteration 9
1085foo::__set_state(array(
1086))
1087foo::__set_state(array(
1088))
1089string(26) "foo::__set_state(array(
1090))"
1091
1092
1093Iteration 10
1094Value::__set_state(array(
1095   'vars' =>
1096  array (
1097  ),
1098))
1099Value::__set_state(array(
1100   'vars' =>
1101  array (
1102  ),
1103))
1104string(57) "Value::__set_state(array(
1105   'vars' =>
1106  array (
1107  ),
1108))"
1109
1110
1111Iteration 11
1112concreteClass::__set_state(array(
1113))
1114concreteClass::__set_state(array(
1115))
1116string(36) "concreteClass::__set_state(array(
1117))"
1118
1119*** Testing var_export() with valid null values ***
1120
1121*** Output for null values ***
1122
1123Iteration 1
1124NULL
1125NULL
1126string(4) "NULL"
1127
1128
1129Iteration 2
1130NULL
1131NULL
1132string(4) "NULL"
1133
1134
1135Iteration 3
1136NULL
1137NULL
1138string(4) "NULL"
1139
1140
1141*** Testing error conditions ***
1142
1143Warning: var_export() expects at least 1 parameter, 0 given in %s on line %d
1144NULL
1145Warning: var_export() expects at most 2 parameters, 3 given in %s on line %d
1146NULL
1147
1148Done
1149