1--TEST--
2Test var_export() function with valid objects
3--FILE--
4<?php
5echo "*** Testing var_export() with valid objects ***\n";
6
7// class with no members
8class foo
9{
10// no members
11}
12
13// abstract class
14abstract class abstractClass
15{
16  abstract protected function getClassName();
17  public function printClassName () {
18    echo $this->getClassName() . "\n";
19  }
20}
21// implement abstract class
22class concreteClass extends abstractClass
23{
24  protected function getClassName() {
25    return "concreteClass";
26  }
27}
28
29// interface class
30interface iValue
31{
32   public function setVal ($name, $val);
33   public function dumpVal ();
34}
35// implement the interface
36class Value implements iValue
37{
38  private $vars = array ();
39
40  public function setVal ( $name, $val ) {
41    $this->vars[$name] = $val;
42  }
43
44  public function dumpVal () {
45    var_export ( $vars );
46  }
47}
48
49// a gereral class
50class myClass
51{
52  var $foo_object;
53  public $public_var;
54  public $public_var1;
55  private $private_var;
56  protected $protected_var;
57
58  function __construct ( ) {
59    $this->foo_object = new foo();
60    $this->public_var = 10;
61    $this->public_var1 = new foo();
62    $this->private_var = new foo();
63    $this->proected_var = new foo();
64  }
65}
66
67// create a object of each class defined above
68$myClass_object = new myClass();
69$foo_object = new foo();
70$Value_object = new Value();
71$concreteClass_object = new concreteClass();
72
73$valid_objects = array(
74                  "new stdclass" => new stdclass,
75                  "new foo" => new foo,
76                  "new concreteClass" => new concreteClass,
77                  "new Value" => new Value,
78                  "new myClass" => new myClass,
79                  "myClass_object" => $myClass_object,
80                  "myClass_object->foo_object" => $myClass_object->foo_object,
81                  "myClass_object->public_var1" => $myClass_object->public_var1,
82                  "foo_object" => $foo_object,
83                  "Value_object" => $Value_object,
84                  "concreteClass_object" => $concreteClass_object
85                 );
86/* Loop to check for above objects with var_export() */
87echo "\n*** Output for objects ***\n";
88foreach($valid_objects as $key => $obj) {
89    echo "\n-- Iteration: $key --\n";
90    var_export( $obj );
91    echo "\n";
92    var_export( $obj, FALSE);
93    echo "\n";
94    var_dump( var_export( $obj, TRUE) );
95    echo "\n";
96}
97?>
98--EXPECT--
99*** Testing var_export() with valid objects ***
100
101*** Output for objects ***
102
103-- Iteration: new stdclass --
104(object) array(
105)
106(object) array(
107)
108string(17) "(object) array(
109)"
110
111
112-- Iteration: new foo --
113foo::__set_state(array(
114))
115foo::__set_state(array(
116))
117string(26) "foo::__set_state(array(
118))"
119
120
121-- Iteration: new concreteClass --
122concreteClass::__set_state(array(
123))
124concreteClass::__set_state(array(
125))
126string(36) "concreteClass::__set_state(array(
127))"
128
129
130-- Iteration: new Value --
131Value::__set_state(array(
132   'vars' =>
133  array (
134  ),
135))
136Value::__set_state(array(
137   'vars' =>
138  array (
139  ),
140))
141string(57) "Value::__set_state(array(
142   'vars' =>
143  array (
144  ),
145))"
146
147
148-- Iteration: new myClass --
149myClass::__set_state(array(
150   'foo_object' =>
151  foo::__set_state(array(
152  )),
153   'public_var' => 10,
154   'public_var1' =>
155  foo::__set_state(array(
156  )),
157   'private_var' =>
158  foo::__set_state(array(
159  )),
160   'protected_var' => NULL,
161   'proected_var' =>
162  foo::__set_state(array(
163  )),
164))
165myClass::__set_state(array(
166   'foo_object' =>
167  foo::__set_state(array(
168  )),
169   'public_var' => 10,
170   'public_var1' =>
171  foo::__set_state(array(
172  )),
173   'private_var' =>
174  foo::__set_state(array(
175  )),
176   'protected_var' => NULL,
177   'proected_var' =>
178  foo::__set_state(array(
179  )),
180))
181string(293) "myClass::__set_state(array(
182   'foo_object' =>
183  foo::__set_state(array(
184  )),
185   'public_var' => 10,
186   'public_var1' =>
187  foo::__set_state(array(
188  )),
189   'private_var' =>
190  foo::__set_state(array(
191  )),
192   'protected_var' => NULL,
193   'proected_var' =>
194  foo::__set_state(array(
195  )),
196))"
197
198
199-- Iteration: myClass_object --
200myClass::__set_state(array(
201   'foo_object' =>
202  foo::__set_state(array(
203  )),
204   'public_var' => 10,
205   'public_var1' =>
206  foo::__set_state(array(
207  )),
208   'private_var' =>
209  foo::__set_state(array(
210  )),
211   'protected_var' => NULL,
212   'proected_var' =>
213  foo::__set_state(array(
214  )),
215))
216myClass::__set_state(array(
217   'foo_object' =>
218  foo::__set_state(array(
219  )),
220   'public_var' => 10,
221   'public_var1' =>
222  foo::__set_state(array(
223  )),
224   'private_var' =>
225  foo::__set_state(array(
226  )),
227   'protected_var' => NULL,
228   'proected_var' =>
229  foo::__set_state(array(
230  )),
231))
232string(293) "myClass::__set_state(array(
233   'foo_object' =>
234  foo::__set_state(array(
235  )),
236   'public_var' => 10,
237   'public_var1' =>
238  foo::__set_state(array(
239  )),
240   'private_var' =>
241  foo::__set_state(array(
242  )),
243   'protected_var' => NULL,
244   'proected_var' =>
245  foo::__set_state(array(
246  )),
247))"
248
249
250-- Iteration: myClass_object->foo_object --
251foo::__set_state(array(
252))
253foo::__set_state(array(
254))
255string(26) "foo::__set_state(array(
256))"
257
258
259-- Iteration: myClass_object->public_var1 --
260foo::__set_state(array(
261))
262foo::__set_state(array(
263))
264string(26) "foo::__set_state(array(
265))"
266
267
268-- Iteration: foo_object --
269foo::__set_state(array(
270))
271foo::__set_state(array(
272))
273string(26) "foo::__set_state(array(
274))"
275
276
277-- Iteration: Value_object --
278Value::__set_state(array(
279   'vars' =>
280  array (
281  ),
282))
283Value::__set_state(array(
284   'vars' =>
285  array (
286  ),
287))
288string(57) "Value::__set_state(array(
289   'vars' =>
290  array (
291  ),
292))"
293
294
295-- Iteration: concreteClass_object --
296concreteClass::__set_state(array(
297))
298concreteClass::__set_state(array(
299))
300string(36) "concreteClass::__set_state(array(
301))"
302
303