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