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