1--TEST--
2Test debug_zval_dump() function : working on objects
3--SKIPIF--
4<?php if (PHP_ZTS) { print "skip only for no-zts build"; }
5--FILE--
6<?php
7/* Prototype: void debug_zval_dump ( mixed $variable );
8   Description: Dumps a string representation of an internal zend value to output.
9*/
10
11/* Prototype: void zval_dump( $value );
12   Description: use debug_zval_dump() to display the objects and its
13                reference count */
14function zval_dump( $values ) {
15  $counter = 1;
16  foreach( $values as $value ) {
17    echo "-- Iteration $counter --\n";
18    debug_zval_dump( $value );
19    $counter++;
20  }
21}
22
23/* checking on objects type */
24echo "*** Testing debug_zval_dump() on objects ***\n";
25class object_class {
26  var $value1 = 1;
27  private $value2 = 10;
28  protected $value3 = 20;
29  public $value4 = 30;
30
31  private function foo1() {
32	echo "function foo1\n";
33  }
34  protected function foo2() {
35	echo "function foo2\n";
36  }
37  public function foo3() {
38	echo "function foo3\n";
39  }
40  public $array_var  = array( "key1" => 1, "key2 " => 3);
41
42  function __construct () {
43      $this->value1 = 5;
44      $this->object_class1 = $this;
45  }
46}
47
48class no_member_class{
49//no members
50}
51
52/* class with member as object of other class */
53class contains_object_class
54{
55   var       $p = 30;
56   protected $p1 = 40;
57   private   $p2 = 50;
58   var       $class_object1;
59   public    $class_object2;
60   private   $class_object3;
61   protected $class_object4;
62   var       $no_member_class_object;
63
64   public function func() {
65     echo "func() is called \n";
66   }
67
68   function __construct () {
69     $this->class_object1 = new object_class();
70     $this->class_object2 = new object_class();
71     $this->class_object3 = $this->class_object1;
72     $this->class_object4 = $this->class_object2;
73     $this->no_member_class_object = new no_member_class();
74     $this->class_object5 = $this;   //recursive reference
75   }
76}
77
78/* creating new object $obj */
79$obj = new contains_object_class();
80$obj1 = & $obj;  //object $obj1 references object $obj
81$obj2 = & $obj;
82$obj3 = & $obj2;
83
84/* object which is unset */
85$unset_obj = new object_class();
86unset($unset_obj);
87
88$objects = array (
89  new object_class,
90  new no_member_class,
91  $obj,
92  $obj->class_object1,
93  $obj->class_object2,
94  $obj->no_member_class_object,
95  @$temp_class_obj,  //undefined object
96  $obj2->class_object1,
97  $obj3->class_object2,
98  $obj2->class_object1->value4,
99  @$unset_obj
100);
101/* using zval_dump() to dump out the objects and its reference count */
102zval_dump($objects);
103
104$int_var = 500;
105$obj = $int_var;  //$obj is lost, $obj1,$obj2,$obj3,$obj4 = 500
106echo "\n-- Testing debug_zval_dump() on overwritten object variables --\n";
107debug_zval_dump($obj, $obj1, $obj2, $obj3);
108
109echo "\n-- Testing debug_zval_dump() on objects having circular reference --\n";
110$recursion_obj1 = new object_class();
111$recursion_obj2 = new object_class();
112$recursion_obj1->obj = &$recursion_obj2;  //circular reference
113$recursion_obj2->obj = &$recursion_obj1;  //circular reference
114debug_zval_dump($recursion_obj2);
115
116echo "Done\n";
117?>
118--EXPECTF--
119*** Testing debug_zval_dump() on objects ***
120-- Iteration 1 --
121object(object_class)#%d (6) refcount(%d){
122  ["value1"]=>
123  int(5)
124  ["value2":"object_class":private]=>
125  int(10)
126  ["value3":protected]=>
127  int(20)
128  ["value4"]=>
129  int(30)
130  ["array_var"]=>
131  array(2) refcount(%d){
132    ["key1"]=>
133    int(1)
134    ["key2 "]=>
135    int(3)
136  }
137  ["object_class1"]=>
138  *RECURSION*
139}
140-- Iteration 2 --
141object(no_member_class)#%d (0) refcount(%d){
142}
143-- Iteration 3 --
144object(contains_object_class)#%d (9) refcount(%d){
145  ["p"]=>
146  int(30)
147  ["p1":protected]=>
148  int(40)
149  ["p2":"contains_object_class":private]=>
150  int(50)
151  ["class_object1"]=>
152  object(object_class)#%d (6) refcount(%d){
153    ["value1"]=>
154    int(5)
155    ["value2":"object_class":private]=>
156    int(10)
157    ["value3":protected]=>
158    int(20)
159    ["value4"]=>
160    int(30)
161    ["array_var"]=>
162    array(2) refcount(%d){
163      ["key1"]=>
164      int(1)
165      ["key2 "]=>
166      int(3)
167    }
168    ["object_class1"]=>
169    *RECURSION*
170  }
171  ["class_object2"]=>
172  object(object_class)#%d (6) refcount(%d){
173    ["value1"]=>
174    int(5)
175    ["value2":"object_class":private]=>
176    int(10)
177    ["value3":protected]=>
178    int(20)
179    ["value4"]=>
180    int(30)
181    ["array_var"]=>
182    array(2) refcount(%d){
183      ["key1"]=>
184      int(1)
185      ["key2 "]=>
186      int(3)
187    }
188    ["object_class1"]=>
189    *RECURSION*
190  }
191  ["class_object3":"contains_object_class":private]=>
192  object(object_class)#%d (6) refcount(%d){
193    ["value1"]=>
194    int(5)
195    ["value2":"object_class":private]=>
196    int(10)
197    ["value3":protected]=>
198    int(20)
199    ["value4"]=>
200    int(30)
201    ["array_var"]=>
202    array(2) refcount(%d){
203      ["key1"]=>
204      int(1)
205      ["key2 "]=>
206      int(3)
207    }
208    ["object_class1"]=>
209    *RECURSION*
210  }
211  ["class_object4":protected]=>
212  object(object_class)#%d (6) refcount(%d){
213    ["value1"]=>
214    int(5)
215    ["value2":"object_class":private]=>
216    int(10)
217    ["value3":protected]=>
218    int(20)
219    ["value4"]=>
220    int(30)
221    ["array_var"]=>
222    array(2) refcount(%d){
223      ["key1"]=>
224      int(1)
225      ["key2 "]=>
226      int(3)
227    }
228    ["object_class1"]=>
229    *RECURSION*
230  }
231  ["no_member_class_object"]=>
232  object(no_member_class)#%d (0) refcount(%d){
233  }
234  ["class_object5"]=>
235  *RECURSION*
236}
237-- Iteration 4 --
238object(object_class)#%d (6) refcount(%d){
239  ["value1"]=>
240  int(5)
241  ["value2":"object_class":private]=>
242  int(10)
243  ["value3":protected]=>
244  int(20)
245  ["value4"]=>
246  int(30)
247  ["array_var"]=>
248  array(2) refcount(%d){
249    ["key1"]=>
250    int(1)
251    ["key2 "]=>
252    int(3)
253  }
254  ["object_class1"]=>
255  *RECURSION*
256}
257-- Iteration 5 --
258object(object_class)#%d (6) refcount(%d){
259  ["value1"]=>
260  int(5)
261  ["value2":"object_class":private]=>
262  int(10)
263  ["value3":protected]=>
264  int(20)
265  ["value4"]=>
266  int(30)
267  ["array_var"]=>
268  array(2) refcount(%d){
269    ["key1"]=>
270    int(1)
271    ["key2 "]=>
272    int(3)
273  }
274  ["object_class1"]=>
275  *RECURSION*
276}
277-- Iteration 6 --
278object(no_member_class)#%d (0) refcount(%d){
279}
280-- Iteration 7 --
281NULL
282-- Iteration 8 --
283object(object_class)#%d (6) refcount(%d){
284  ["value1"]=>
285  int(5)
286  ["value2":"object_class":private]=>
287  int(10)
288  ["value3":protected]=>
289  int(20)
290  ["value4"]=>
291  int(30)
292  ["array_var"]=>
293  array(2) refcount(%d){
294    ["key1"]=>
295    int(1)
296    ["key2 "]=>
297    int(3)
298  }
299  ["object_class1"]=>
300  *RECURSION*
301}
302-- Iteration 9 --
303object(object_class)#%d (6) refcount(%d){
304  ["value1"]=>
305  int(5)
306  ["value2":"object_class":private]=>
307  int(10)
308  ["value3":protected]=>
309  int(20)
310  ["value4"]=>
311  int(30)
312  ["array_var"]=>
313  array(2) refcount(%d){
314    ["key1"]=>
315    int(1)
316    ["key2 "]=>
317    int(3)
318  }
319  ["object_class1"]=>
320  *RECURSION*
321}
322-- Iteration 10 --
323int(30)
324-- Iteration 11 --
325NULL
326
327-- Testing debug_zval_dump() on overwritten object variables --
328int(500)
329int(500)
330int(500)
331int(500)
332
333-- Testing debug_zval_dump() on objects having circular reference --
334object(object_class)#%d (7) refcount(%d){
335  ["value1"]=>
336  int(5)
337  ["value2":"object_class":private]=>
338  int(10)
339  ["value3":protected]=>
340  int(20)
341  ["value4"]=>
342  int(30)
343  ["array_var"]=>
344  array(2) refcount(%d){
345    ["key1"]=>
346    int(1)
347    ["key2 "]=>
348    int(3)
349  }
350  ["object_class1"]=>
351  *RECURSION*
352  ["obj"]=>
353  &object(object_class)#%d (7) refcount(%d){
354    ["value1"]=>
355    int(5)
356    ["value2":"object_class":private]=>
357    int(10)
358    ["value3":protected]=>
359    int(20)
360    ["value4"]=>
361    int(30)
362    ["array_var"]=>
363    array(2) refcount(%d){
364      ["key1"]=>
365      int(1)
366      ["key2 "]=>
367      int(3)
368    }
369    ["object_class1"]=>
370    *RECURSION*
371    ["obj"]=>
372    *RECURSION*
373  }
374}
375Done
376