1--TEST--
2Test debug_zval_dump() function : working on objects
3--FILE--
4<?php
5/* Prototype: void debug_zval_dump ( mixed $variable );
6   Description: Dumps a string representation of an internal zend value to output.
7*/
8
9/* Prototype: void zval_dump( $value );
10   Description: use debug_zval_dump() to display the objects and its
11                reference count */
12function zval_dump( $values ) {
13  $counter = 1;
14  foreach( $values as $value ) {
15    echo "-- Iteration $counter --\n";
16    debug_zval_dump( $value );
17    $counter++;
18  }
19}
20
21/* checking on objects type */
22echo "*** Testing debug_zval_dump() on objects ***\n";
23class object_class {
24  var $value1 = 1;
25  private $value2 = 10;
26  protected $value3 = 20;
27  public $value4 = 30;
28
29  private function foo1() {
30	echo "function foo1\n";
31  }
32  protected function foo2() {
33	echo "function foo2\n";
34  }
35  public function foo3() {
36	echo "function foo3\n";
37  }
38  public $array_var  = array( "key1" => 1, "key2 " => 3);
39
40  function object_class () {
41      $this->value1 = 5;
42      $this->object_class1 = $this;
43  }
44}
45
46class no_member_class{
47//no members
48}
49
50/* class with member as object of other class */
51class contains_object_class
52{
53   var       $p = 30;
54   protected $p1 = 40;
55   private   $p2 = 50;
56   var       $class_object1;
57   public    $class_object2;
58   private   $class_object3;
59   protected $class_object4;
60   var       $no_member_class_object;
61
62   public function func() {
63     echo "func() is called \n";
64   }
65
66   function contains_object_class () {
67     $this->class_object1 = new object_class();
68     $this->class_object2 = new object_class();
69     $this->class_object3 = $this->class_object1;
70     $this->class_object4 = $this->class_object2;
71     $this->no_member_class_object = new no_member_class();
72     $this->class_object5 = $this;   //recursive reference
73   }
74}
75
76/* creating new object $obj */
77$obj = new contains_object_class();
78$obj1 = & $obj;  //object $obj1 references object $obj
79$obj2 = & $obj;
80$obj3 = & $obj2;
81
82/* object which is unset */
83$unset_obj = new object_class();
84unset($unset_obj);
85
86$objects = array (
87  new object_class,
88  new no_member_class,
89  $obj,
90  $obj->class_object1,
91  $obj->class_object2,
92  $obj->no_member_class_object,
93  @$temp_class_obj,  //undefined object
94  $obj2->class_object1,
95  $obj3->class_object2,
96  $obj2->class_object1->value4,
97  @$unset_obj
98);
99/* using zval_dump() to dump out the objects and its reference count */
100zval_dump($objects);
101
102$int_var = 500;
103$obj = $int_var;  //$obj is lost, $obj1,$obj2,$obj3,$obj4 = 500
104echo "\n-- Testing debug_zval_dump() on overwritten object variables --\n";
105debug_zval_dump($obj, $obj1, $obj2, $obj3);
106
107echo "\n-- Testing debug_zval_dump() on objects having circular reference --\n";
108$recursion_obj1 = new object_class();
109$recursion_obj2 = new object_class();
110$recursion_obj1->obj = &$recursion_obj2;  //circular reference
111$recursion_obj2->obj = &$recursion_obj1;  //circular reference
112debug_zval_dump($recursion_obj2);
113
114echo "Done\n";
115?>
116--EXPECTF--
117*** Testing debug_zval_dump() on objects ***
118-- Iteration 1 --
119object(object_class)#%d (6) refcount(5){
120  ["value1"]=>
121  long(5) refcount(1)
122  ["value2":"object_class":private]=>
123  long(10) refcount(5)
124  ["value3":protected]=>
125  long(20) refcount(5)
126  ["value4"]=>
127  long(30) refcount(7)
128  ["array_var"]=>
129  array(2) refcount(5){
130    ["key1"]=>
131    long(1) refcount(1)
132    ["key2 "]=>
133    long(3) refcount(1)
134  }
135  ["object_class1"]=>
136  object(object_class)#%d (6) refcount(5){
137    ["value1"]=>
138    long(5) refcount(1)
139    ["value2":"object_class":private]=>
140    long(10) refcount(5)
141    ["value3":protected]=>
142    long(20) refcount(5)
143    ["value4"]=>
144    long(30) refcount(7)
145    ["array_var"]=>
146    array(2) refcount(5){
147      ["key1"]=>
148      long(1) refcount(1)
149      ["key2 "]=>
150      long(3) refcount(1)
151    }
152    ["object_class1"]=>
153    *RECURSION*
154  }
155}
156-- Iteration 2 --
157object(no_member_class)#%d (0) refcount(4){
158}
159-- Iteration 3 --
160object(contains_object_class)#%d (9) refcount(4){
161  ["p"]=>
162  long(30) refcount(2)
163  ["p1":protected]=>
164  long(40) refcount(2)
165  ["p2":"contains_object_class":private]=>
166  long(50) refcount(2)
167  ["class_object1"]=>
168  object(object_class)#%d (6) refcount(7){
169    ["value1"]=>
170    long(5) refcount(1)
171    ["value2":"object_class":private]=>
172    long(10) refcount(5)
173    ["value3":protected]=>
174    long(20) refcount(5)
175    ["value4"]=>
176    long(30) refcount(7)
177    ["array_var"]=>
178    array(2) refcount(5){
179      ["key1"]=>
180      long(1) refcount(1)
181      ["key2 "]=>
182      long(3) refcount(1)
183    }
184    ["object_class1"]=>
185    object(object_class)#%d (6) refcount(7){
186      ["value1"]=>
187      long(5) refcount(1)
188      ["value2":"object_class":private]=>
189      long(10) refcount(5)
190      ["value3":protected]=>
191      long(20) refcount(5)
192      ["value4"]=>
193      long(30) refcount(7)
194      ["array_var"]=>
195      array(2) refcount(5){
196        ["key1"]=>
197        long(1) refcount(1)
198        ["key2 "]=>
199        long(3) refcount(1)
200      }
201      ["object_class1"]=>
202      *RECURSION*
203    }
204  }
205  ["class_object2"]=>
206  object(object_class)#%d (6) refcount(7){
207    ["value1"]=>
208    long(5) refcount(1)
209    ["value2":"object_class":private]=>
210    long(10) refcount(5)
211    ["value3":protected]=>
212    long(20) refcount(5)
213    ["value4"]=>
214    long(30) refcount(7)
215    ["array_var"]=>
216    array(2) refcount(5){
217      ["key1"]=>
218      long(1) refcount(1)
219      ["key2 "]=>
220      long(3) refcount(1)
221    }
222    ["object_class1"]=>
223    object(object_class)#%d (6) refcount(7){
224      ["value1"]=>
225      long(5) refcount(1)
226      ["value2":"object_class":private]=>
227      long(10) refcount(5)
228      ["value3":protected]=>
229      long(20) refcount(5)
230      ["value4"]=>
231      long(30) refcount(7)
232      ["array_var"]=>
233      array(2) refcount(5){
234        ["key1"]=>
235        long(1) refcount(1)
236        ["key2 "]=>
237        long(3) refcount(1)
238      }
239      ["object_class1"]=>
240      *RECURSION*
241    }
242  }
243  ["class_object3":"contains_object_class":private]=>
244  object(object_class)#%d (6) refcount(7){
245    ["value1"]=>
246    long(5) refcount(1)
247    ["value2":"object_class":private]=>
248    long(10) refcount(5)
249    ["value3":protected]=>
250    long(20) refcount(5)
251    ["value4"]=>
252    long(30) refcount(7)
253    ["array_var"]=>
254    array(2) refcount(5){
255      ["key1"]=>
256      long(1) refcount(1)
257      ["key2 "]=>
258      long(3) refcount(1)
259    }
260    ["object_class1"]=>
261    object(object_class)#%d (6) refcount(7){
262      ["value1"]=>
263      long(5) refcount(1)
264      ["value2":"object_class":private]=>
265      long(10) refcount(5)
266      ["value3":protected]=>
267      long(20) refcount(5)
268      ["value4"]=>
269      long(30) refcount(7)
270      ["array_var"]=>
271      array(2) refcount(5){
272        ["key1"]=>
273        long(1) refcount(1)
274        ["key2 "]=>
275        long(3) refcount(1)
276      }
277      ["object_class1"]=>
278      *RECURSION*
279    }
280  }
281  ["class_object4":protected]=>
282  object(object_class)#%d (6) refcount(7){
283    ["value1"]=>
284    long(5) refcount(1)
285    ["value2":"object_class":private]=>
286    long(10) refcount(5)
287    ["value3":protected]=>
288    long(20) refcount(5)
289    ["value4"]=>
290    long(30) refcount(7)
291    ["array_var"]=>
292    array(2) refcount(5){
293      ["key1"]=>
294      long(1) refcount(1)
295      ["key2 "]=>
296      long(3) refcount(1)
297    }
298    ["object_class1"]=>
299    object(object_class)#%d (6) refcount(7){
300      ["value1"]=>
301      long(5) refcount(1)
302      ["value2":"object_class":private]=>
303      long(10) refcount(5)
304      ["value3":protected]=>
305      long(20) refcount(5)
306      ["value4"]=>
307      long(30) refcount(7)
308      ["array_var"]=>
309      array(2) refcount(5){
310        ["key1"]=>
311        long(1) refcount(1)
312        ["key2 "]=>
313        long(3) refcount(1)
314      }
315      ["object_class1"]=>
316      *RECURSION*
317    }
318  }
319  ["no_member_class_object"]=>
320  object(no_member_class)#%d (0) refcount(3){
321  }
322  ["class_object5"]=>
323  object(contains_object_class)#%d (9) refcount(1){
324    ["p"]=>
325    long(30) refcount(2)
326    ["p1":protected]=>
327    long(40) refcount(2)
328    ["p2":"contains_object_class":private]=>
329    long(50) refcount(2)
330    ["class_object1"]=>
331    object(object_class)#%d (6) refcount(7){
332      ["value1"]=>
333      long(5) refcount(1)
334      ["value2":"object_class":private]=>
335      long(10) refcount(5)
336      ["value3":protected]=>
337      long(20) refcount(5)
338      ["value4"]=>
339      long(30) refcount(7)
340      ["array_var"]=>
341      array(2) refcount(5){
342        ["key1"]=>
343        long(1) refcount(1)
344        ["key2 "]=>
345        long(3) refcount(1)
346      }
347      ["object_class1"]=>
348      object(object_class)#%d (6) refcount(7){
349        ["value1"]=>
350        long(5) refcount(1)
351        ["value2":"object_class":private]=>
352        long(10) refcount(5)
353        ["value3":protected]=>
354        long(20) refcount(5)
355        ["value4"]=>
356        long(30) refcount(7)
357        ["array_var"]=>
358        array(2) refcount(5){
359          ["key1"]=>
360          long(1) refcount(1)
361          ["key2 "]=>
362          long(3) refcount(1)
363        }
364        ["object_class1"]=>
365        *RECURSION*
366      }
367    }
368    ["class_object2"]=>
369    object(object_class)#%d (6) refcount(7){
370      ["value1"]=>
371      long(5) refcount(1)
372      ["value2":"object_class":private]=>
373      long(10) refcount(5)
374      ["value3":protected]=>
375      long(20) refcount(5)
376      ["value4"]=>
377      long(30) refcount(7)
378      ["array_var"]=>
379      array(2) refcount(5){
380        ["key1"]=>
381        long(1) refcount(1)
382        ["key2 "]=>
383        long(3) refcount(1)
384      }
385      ["object_class1"]=>
386      object(object_class)#%d (6) refcount(7){
387        ["value1"]=>
388        long(5) refcount(1)
389        ["value2":"object_class":private]=>
390        long(10) refcount(5)
391        ["value3":protected]=>
392        long(20) refcount(5)
393        ["value4"]=>
394        long(30) refcount(7)
395        ["array_var"]=>
396        array(2) refcount(5){
397          ["key1"]=>
398          long(1) refcount(1)
399          ["key2 "]=>
400          long(3) refcount(1)
401        }
402        ["object_class1"]=>
403        *RECURSION*
404      }
405    }
406    ["class_object3":"contains_object_class":private]=>
407    object(object_class)#%d (6) refcount(7){
408      ["value1"]=>
409      long(5) refcount(1)
410      ["value2":"object_class":private]=>
411      long(10) refcount(5)
412      ["value3":protected]=>
413      long(20) refcount(5)
414      ["value4"]=>
415      long(30) refcount(7)
416      ["array_var"]=>
417      array(2) refcount(5){
418        ["key1"]=>
419        long(1) refcount(1)
420        ["key2 "]=>
421        long(3) refcount(1)
422      }
423      ["object_class1"]=>
424      object(object_class)#%d (6) refcount(7){
425        ["value1"]=>
426        long(5) refcount(1)
427        ["value2":"object_class":private]=>
428        long(10) refcount(5)
429        ["value3":protected]=>
430        long(20) refcount(5)
431        ["value4"]=>
432        long(30) refcount(7)
433        ["array_var"]=>
434        array(2) refcount(5){
435          ["key1"]=>
436          long(1) refcount(1)
437          ["key2 "]=>
438          long(3) refcount(1)
439        }
440        ["object_class1"]=>
441        *RECURSION*
442      }
443    }
444    ["class_object4":protected]=>
445    object(object_class)#%d (6) refcount(7){
446      ["value1"]=>
447      long(5) refcount(1)
448      ["value2":"object_class":private]=>
449      long(10) refcount(5)
450      ["value3":protected]=>
451      long(20) refcount(5)
452      ["value4"]=>
453      long(30) refcount(7)
454      ["array_var"]=>
455      array(2) refcount(5){
456        ["key1"]=>
457        long(1) refcount(1)
458        ["key2 "]=>
459        long(3) refcount(1)
460      }
461      ["object_class1"]=>
462      object(object_class)#%d (6) refcount(7){
463        ["value1"]=>
464        long(5) refcount(1)
465        ["value2":"object_class":private]=>
466        long(10) refcount(5)
467        ["value3":protected]=>
468        long(20) refcount(5)
469        ["value4"]=>
470        long(30) refcount(7)
471        ["array_var"]=>
472        array(2) refcount(5){
473          ["key1"]=>
474          long(1) refcount(1)
475          ["key2 "]=>
476          long(3) refcount(1)
477        }
478        ["object_class1"]=>
479        *RECURSION*
480      }
481    }
482    ["no_member_class_object"]=>
483    object(no_member_class)#%d (0) refcount(3){
484    }
485    ["class_object5"]=>
486    *RECURSION*
487  }
488}
489-- Iteration 4 --
490object(object_class)#%d (6) refcount(9){
491  ["value1"]=>
492  long(5) refcount(1)
493  ["value2":"object_class":private]=>
494  long(10) refcount(5)
495  ["value3":protected]=>
496  long(20) refcount(5)
497  ["value4"]=>
498  long(30) refcount(7)
499  ["array_var"]=>
500  array(2) refcount(5){
501    ["key1"]=>
502    long(1) refcount(1)
503    ["key2 "]=>
504    long(3) refcount(1)
505  }
506  ["object_class1"]=>
507  object(object_class)#%d (6) refcount(9){
508    ["value1"]=>
509    long(5) refcount(1)
510    ["value2":"object_class":private]=>
511    long(10) refcount(5)
512    ["value3":protected]=>
513    long(20) refcount(5)
514    ["value4"]=>
515    long(30) refcount(7)
516    ["array_var"]=>
517    array(2) refcount(5){
518      ["key1"]=>
519      long(1) refcount(1)
520      ["key2 "]=>
521      long(3) refcount(1)
522    }
523    ["object_class1"]=>
524    *RECURSION*
525  }
526}
527-- Iteration 5 --
528object(object_class)#%d (6) refcount(9){
529  ["value1"]=>
530  long(5) refcount(1)
531  ["value2":"object_class":private]=>
532  long(10) refcount(5)
533  ["value3":protected]=>
534  long(20) refcount(5)
535  ["value4"]=>
536  long(30) refcount(7)
537  ["array_var"]=>
538  array(2) refcount(5){
539    ["key1"]=>
540    long(1) refcount(1)
541    ["key2 "]=>
542    long(3) refcount(1)
543  }
544  ["object_class1"]=>
545  object(object_class)#%d (6) refcount(9){
546    ["value1"]=>
547    long(5) refcount(1)
548    ["value2":"object_class":private]=>
549    long(10) refcount(5)
550    ["value3":protected]=>
551    long(20) refcount(5)
552    ["value4"]=>
553    long(30) refcount(7)
554    ["array_var"]=>
555    array(2) refcount(5){
556      ["key1"]=>
557      long(1) refcount(1)
558      ["key2 "]=>
559      long(3) refcount(1)
560    }
561    ["object_class1"]=>
562    *RECURSION*
563  }
564}
565-- Iteration 6 --
566object(no_member_class)#%d (0) refcount(5){
567}
568-- Iteration 7 --
569NULL refcount(1)
570-- Iteration 8 --
571object(object_class)#%d (6) refcount(9){
572  ["value1"]=>
573  long(5) refcount(1)
574  ["value2":"object_class":private]=>
575  long(10) refcount(5)
576  ["value3":protected]=>
577  long(20) refcount(5)
578  ["value4"]=>
579  long(30) refcount(7)
580  ["array_var"]=>
581  array(2) refcount(5){
582    ["key1"]=>
583    long(1) refcount(1)
584    ["key2 "]=>
585    long(3) refcount(1)
586  }
587  ["object_class1"]=>
588  object(object_class)#%d (6) refcount(9){
589    ["value1"]=>
590    long(5) refcount(1)
591    ["value2":"object_class":private]=>
592    long(10) refcount(5)
593    ["value3":protected]=>
594    long(20) refcount(5)
595    ["value4"]=>
596    long(30) refcount(7)
597    ["array_var"]=>
598    array(2) refcount(5){
599      ["key1"]=>
600      long(1) refcount(1)
601      ["key2 "]=>
602      long(3) refcount(1)
603    }
604    ["object_class1"]=>
605    *RECURSION*
606  }
607}
608-- Iteration 9 --
609object(object_class)#%d (6) refcount(9){
610  ["value1"]=>
611  long(5) refcount(1)
612  ["value2":"object_class":private]=>
613  long(10) refcount(5)
614  ["value3":protected]=>
615  long(20) refcount(5)
616  ["value4"]=>
617  long(30) refcount(7)
618  ["array_var"]=>
619  array(2) refcount(5){
620    ["key1"]=>
621    long(1) refcount(1)
622    ["key2 "]=>
623    long(3) refcount(1)
624  }
625  ["object_class1"]=>
626  object(object_class)#%d (6) refcount(9){
627    ["value1"]=>
628    long(5) refcount(1)
629    ["value2":"object_class":private]=>
630    long(10) refcount(5)
631    ["value3":protected]=>
632    long(20) refcount(5)
633    ["value4"]=>
634    long(30) refcount(7)
635    ["array_var"]=>
636    array(2) refcount(5){
637      ["key1"]=>
638      long(1) refcount(1)
639      ["key2 "]=>
640      long(3) refcount(1)
641    }
642    ["object_class1"]=>
643    *RECURSION*
644  }
645}
646-- Iteration 10 --
647long(30) refcount(9)
648-- Iteration 11 --
649NULL refcount(1)
650
651-- Testing debug_zval_dump() on overwritten object variables --
652long(500) refcount(1)
653long(500) refcount(1)
654long(500) refcount(1)
655long(500) refcount(1)
656
657-- Testing debug_zval_dump() on objects having circular reference --
658object(object_class)#%d (7) refcount(1){
659  ["value1"]=>
660  long(5) refcount(1)
661  ["value2":"object_class":private]=>
662  long(10) refcount(7)
663  ["value3":protected]=>
664  long(20) refcount(7)
665  ["value4"]=>
666  long(30) refcount(8)
667  ["array_var"]=>
668  array(2) refcount(7){
669    ["key1"]=>
670    long(1) refcount(1)
671    ["key2 "]=>
672    long(3) refcount(1)
673  }
674  ["object_class1"]=>
675  object(object_class)#%d (7) refcount(1){
676    ["value1"]=>
677    long(5) refcount(1)
678    ["value2":"object_class":private]=>
679    long(10) refcount(7)
680    ["value3":protected]=>
681    long(20) refcount(7)
682    ["value4"]=>
683    long(30) refcount(8)
684    ["array_var"]=>
685    array(2) refcount(7){
686      ["key1"]=>
687      long(1) refcount(1)
688      ["key2 "]=>
689      long(3) refcount(1)
690    }
691    ["object_class1"]=>
692    *RECURSION*
693    ["obj"]=>
694    &object(object_class)#%d (7) refcount(2){
695      ["value1"]=>
696      long(5) refcount(1)
697      ["value2":"object_class":private]=>
698      long(10) refcount(7)
699      ["value3":protected]=>
700      long(20) refcount(7)
701      ["value4"]=>
702      long(30) refcount(8)
703      ["array_var"]=>
704      array(2) refcount(7){
705        ["key1"]=>
706        long(1) refcount(1)
707        ["key2 "]=>
708        long(3) refcount(1)
709      }
710      ["object_class1"]=>
711      object(object_class)#%d (7) refcount(1){
712        ["value1"]=>
713        long(5) refcount(1)
714        ["value2":"object_class":private]=>
715        long(10) refcount(7)
716        ["value3":protected]=>
717        long(20) refcount(7)
718        ["value4"]=>
719        long(30) refcount(8)
720        ["array_var"]=>
721        array(2) refcount(7){
722          ["key1"]=>
723          long(1) refcount(1)
724          ["key2 "]=>
725          long(3) refcount(1)
726        }
727        ["object_class1"]=>
728        *RECURSION*
729        ["obj"]=>
730        *RECURSION*
731      }
732      ["obj"]=>
733      *RECURSION*
734    }
735  }
736  ["obj"]=>
737  &object(object_class)#%d (7) refcount(2){
738    ["value1"]=>
739    long(5) refcount(1)
740    ["value2":"object_class":private]=>
741    long(10) refcount(7)
742    ["value3":protected]=>
743    long(20) refcount(7)
744    ["value4"]=>
745    long(30) refcount(8)
746    ["array_var"]=>
747    array(2) refcount(7){
748      ["key1"]=>
749      long(1) refcount(1)
750      ["key2 "]=>
751      long(3) refcount(1)
752    }
753    ["object_class1"]=>
754    object(object_class)#%d (7) refcount(1){
755      ["value1"]=>
756      long(5) refcount(1)
757      ["value2":"object_class":private]=>
758      long(10) refcount(7)
759      ["value3":protected]=>
760      long(20) refcount(7)
761      ["value4"]=>
762      long(30) refcount(8)
763      ["array_var"]=>
764      array(2) refcount(7){
765        ["key1"]=>
766        long(1) refcount(1)
767        ["key2 "]=>
768        long(3) refcount(1)
769      }
770      ["object_class1"]=>
771      *RECURSION*
772      ["obj"]=>
773      &object(object_class)#%d (7) refcount(2){
774        ["value1"]=>
775        long(5) refcount(1)
776        ["value2":"object_class":private]=>
777        long(10) refcount(7)
778        ["value3":protected]=>
779        long(20) refcount(7)
780        ["value4"]=>
781        long(30) refcount(8)
782        ["array_var"]=>
783        array(2) refcount(7){
784          ["key1"]=>
785          long(1) refcount(1)
786          ["key2 "]=>
787          long(3) refcount(1)
788        }
789        ["object_class1"]=>
790        *RECURSION*
791        ["obj"]=>
792        *RECURSION*
793      }
794    }
795    ["obj"]=>
796    &object(object_class)#%d (7) refcount(2){
797      ["value1"]=>
798      long(5) refcount(1)
799      ["value2":"object_class":private]=>
800      long(10) refcount(7)
801      ["value3":protected]=>
802      long(20) refcount(7)
803      ["value4"]=>
804      long(30) refcount(8)
805      ["array_var"]=>
806      array(2) refcount(7){
807        ["key1"]=>
808        long(1) refcount(1)
809        ["key2 "]=>
810        long(3) refcount(1)
811      }
812      ["object_class1"]=>
813      *RECURSION*
814      ["obj"]=>
815      &object(object_class)#%d (7) refcount(2){
816        ["value1"]=>
817        long(5) refcount(1)
818        ["value2":"object_class":private]=>
819        long(10) refcount(7)
820        ["value3":protected]=>
821        long(20) refcount(7)
822        ["value4"]=>
823        long(30) refcount(8)
824        ["array_var"]=>
825        array(2) refcount(7){
826          ["key1"]=>
827          long(1) refcount(1)
828          ["key2 "]=>
829          long(3) refcount(1)
830        }
831        ["object_class1"]=>
832        *RECURSION*
833        ["obj"]=>
834        *RECURSION*
835      }
836    }
837  }
838}
839Done
840