1--TEST--
2Test var_export() function with locale
3--INI--
4precision=14
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                -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() */
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  -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() */
105echo "\n*** Output for float values ***\n";
106foreach($valid_bool 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 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() */
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
4701
4711
472string(1) "1"
473
474
475Iteration 2
476true
477true
478string(4) "true"
479
480
481Iteration 3
482true
483true
484string(4) "true"
485
486
487Iteration 4
4880
4890
490string(1) "0"
491
492
493Iteration 5
494false
495false
496string(5) "false"
497
498
499Iteration 6
500false
501false
502string(5) "false"
503
504*** Testing var_export() with valid strings ***
505
506*** Output for strings ***
507
508Iteration 1
509''
510''
511string(2) "''"
512
513
514Iteration 2
515' '
516' '
517string(3) "' '"
518
519
520Iteration 3
521''
522''
523string(2) "''"
524
525
526Iteration 4
527' '
528' '
529string(3) "' '"
530
531
532Iteration 5
533'string'
534'string'
535string(8) "'string'"
536
537
538Iteration 6
539'string'
540'string'
541string(8) "'string'"
542
543
544Iteration 7
545'NULL'
546'NULL'
547string(6) "'NULL'"
548
549
550Iteration 8
551'null'
552'null'
553string(6) "'null'"
554
555
556Iteration 9
557'FALSE'
558'FALSE'
559string(7) "'FALSE'"
560
561
562Iteration 10
563'false'
564'false'
565string(7) "'false'"
566
567
568Iteration 11
569''
570''
571string(3) "''"
572
573
574Iteration 12
575'' . "\0" . ''
576'' . "\0" . ''
577string(14) "'' . "\0" . ''"
578
579
580Iteration 13
581'\\0'
582'\\0'
583string(5) "'\\0'"
584
585
586Iteration 14
587'\\060'
588'\\060'
589string(7) "'\\060'"
590
591
592Iteration 15
593'8'
594'8'
595string(3) "'8'"
596
597*** Testing var_export() with valid arrays ***
598
599*** Output for arrays ***
600
601Iteration 1
602array (
603)
604array (
605)
606string(9) "array (
607)"
608
609
610Iteration 2
611array (
612  0 => NULL,
613)
614array (
615  0 => NULL,
616)
617string(22) "array (
618  0 => NULL,
619)"
620
621
622Iteration 3
623array (
624  0 => NULL,
625)
626array (
627  0 => NULL,
628)
629string(22) "array (
630  0 => NULL,
631)"
632
633
634Iteration 4
635array (
636  0 => true,
637)
638array (
639  0 => true,
640)
641string(22) "array (
642  0 => true,
643)"
644
645
646Iteration 5
647array (
648  0 => '',
649)
650array (
651  0 => '',
652)
653string(20) "array (
654  0 => '',
655)"
656
657
658Iteration 6
659array (
660  0 => '',
661)
662array (
663  0 => '',
664)
665string(20) "array (
666  0 => '',
667)"
668
669
670Iteration 7
671array (
672  0 =>
673  array (
674  ),
675  1 =>
676  array (
677  ),
678)
679array (
680  0 =>
681  array (
682  ),
683  1 =>
684  array (
685  ),
686)
687string(55) "array (
688  0 =>
689  array (
690  ),
691  1 =>
692  array (
693  ),
694)"
695
696
697Iteration 8
698array (
699  0 =>
700  array (
701    0 => 1,
702    1 => 2,
703  ),
704  1 =>
705  array (
706    0 => 'a',
707    1 => 'b',
708  ),
709)
710array (
711  0 =>
712  array (
713    0 => 1,
714    1 => 2,
715  ),
716  1 =>
717  array (
718    0 => 'a',
719    1 => 'b',
720  ),
721)
722string(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
736Iteration 9
737array (
738  1 => 'One',
739)
740array (
741  1 => 'One',
742)
743string(23) "array (
744  1 => 'One',
745)"
746
747
748Iteration 10
749array (
750  'test' => 'is_array',
751)
752array (
753  'test' => 'is_array',
754)
755string(33) "array (
756  'test' => 'is_array',
757)"
758
759
760Iteration 11
761array (
762  0 => 0,
763)
764array (
765  0 => 0,
766)
767string(19) "array (
768  0 => 0,
769)"
770
771
772Iteration 12
773array (
774  0 => -1,
775)
776array (
777  0 => -1,
778)
779string(20) "array (
780  0 => -1,
781)"
782
783
784Iteration 13
785array (
786  0 => 10.5,
787  1 => 5.6,
788)
789array (
790  0 => 10.5,
791  1 => 5.6,
792)
793string(34) "array (
794  0 => 10.5,
795  1 => 5.6,
796)"
797
798
799Iteration 14
800array (
801  0 => 'string',
802  1 => 'test',
803)
804array (
805  0 => 'string',
806  1 => 'test',
807)
808string(41) "array (
809  0 => 'string',
810  1 => 'test',
811)"
812
813
814Iteration 15
815array (
816  0 => 'string',
817  1 => 'test',
818)
819array (
820  0 => 'string',
821  1 => 'test',
822)
823string(41) "array (
824  0 => 'string',
825  1 => 'test',
826)"
827
828*** Testing var_export() with valid objects ***
829
830*** Output for objects ***
831
832Iteration 1
833stdClass::__set_state(array(
834))
835stdClass::__set_state(array(
836))
837string(31) "stdClass::__set_state(array(
838))"
839
840
841Iteration 2
842foo::__set_state(array(
843))
844foo::__set_state(array(
845))
846string(26) "foo::__set_state(array(
847))"
848
849
850Iteration 3
851concreteClass::__set_state(array(
852))
853concreteClass::__set_state(array(
854))
855string(36) "concreteClass::__set_state(array(
856))"
857
858
859Iteration 4
860Value::__set_state(array(
861   'vars' =>
862  array (
863  ),
864))
865Value::__set_state(array(
866   'vars' =>
867  array (
868  ),
869))
870string(57) "Value::__set_state(array(
871   'vars' =>
872  array (
873  ),
874))"
875
876
877Iteration 5
878myClass::__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))
894myClass::__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))
910string(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
928Iteration 6
929myClass::__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))
945myClass::__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))
961string(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
979Iteration 7
980foo::__set_state(array(
981))
982foo::__set_state(array(
983))
984string(26) "foo::__set_state(array(
985))"
986
987
988Iteration 8
989foo::__set_state(array(
990))
991foo::__set_state(array(
992))
993string(26) "foo::__set_state(array(
994))"
995
996
997Iteration 9
998foo::__set_state(array(
999))
1000foo::__set_state(array(
1001))
1002string(26) "foo::__set_state(array(
1003))"
1004
1005
1006Iteration 10
1007Value::__set_state(array(
1008   'vars' =>
1009  array (
1010  ),
1011))
1012Value::__set_state(array(
1013   'vars' =>
1014  array (
1015  ),
1016))
1017string(57) "Value::__set_state(array(
1018   'vars' =>
1019  array (
1020  ),
1021))"
1022
1023
1024Iteration 11
1025concreteClass::__set_state(array(
1026))
1027concreteClass::__set_state(array(
1028))
1029string(36) "concreteClass::__set_state(array(
1030))"
1031
1032*** Testing var_export() with valid null values ***
1033
1034*** Output for null values ***
1035
1036Iteration 1
1037NULL
1038NULL
1039string(4) "NULL"
1040
1041
1042Iteration 2
1043NULL
1044NULL
1045string(4) "NULL"
1046
1047
1048Iteration 3
1049NULL
1050NULL
1051string(4) "NULL"
1052
1053
1054*** Testing error conditions ***
1055
1056Warning: var_export() expects at least 1 parameter, 0 given in %s on line %d
1057NULL
1058Warning: var_export() expects at most 2 parameters, 3 given in %s on line %d
1059NULL
1060
1061Done
1062