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  object(object_class)#%d (6) refcount(%d){
139    ["value1"]=>
140    int(5)
141    ["value2":"object_class":private]=>
142    int(10)
143    ["value3":protected]=>
144    int(20)
145    ["value4"]=>
146    int(30)
147    ["array_var"]=>
148    array(2) refcount(%d){
149      ["key1"]=>
150      int(1)
151      ["key2 "]=>
152      int(3)
153    }
154    ["object_class1"]=>
155    *RECURSION*
156  }
157}
158-- Iteration 2 --
159object(no_member_class)#%d (0) refcount(%d){
160}
161-- Iteration 3 --
162object(contains_object_class)#%d (9) refcount(%d){
163  ["p"]=>
164  int(30)
165  ["p1":protected]=>
166  int(40)
167  ["p2":"contains_object_class":private]=>
168  int(50)
169  ["class_object1"]=>
170  object(object_class)#%d (6) refcount(%d){
171    ["value1"]=>
172    int(5)
173    ["value2":"object_class":private]=>
174    int(10)
175    ["value3":protected]=>
176    int(20)
177    ["value4"]=>
178    int(30)
179    ["array_var"]=>
180    array(2) refcount(%d){
181      ["key1"]=>
182      int(1)
183      ["key2 "]=>
184      int(3)
185    }
186    ["object_class1"]=>
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  }
207  ["class_object2"]=>
208  object(object_class)#%d (6) refcount(%d){
209    ["value1"]=>
210    int(5)
211    ["value2":"object_class":private]=>
212    int(10)
213    ["value3":protected]=>
214    int(20)
215    ["value4"]=>
216    int(30)
217    ["array_var"]=>
218    array(2) refcount(%d){
219      ["key1"]=>
220      int(1)
221      ["key2 "]=>
222      int(3)
223    }
224    ["object_class1"]=>
225    object(object_class)#%d (6) refcount(%d){
226      ["value1"]=>
227      int(5)
228      ["value2":"object_class":private]=>
229      int(10)
230      ["value3":protected]=>
231      int(20)
232      ["value4"]=>
233      int(30)
234      ["array_var"]=>
235      array(2) refcount(%d){
236        ["key1"]=>
237        int(1)
238        ["key2 "]=>
239        int(3)
240      }
241      ["object_class1"]=>
242      *RECURSION*
243    }
244  }
245  ["class_object3":"contains_object_class":private]=>
246  object(object_class)#%d (6) refcount(%d){
247    ["value1"]=>
248    int(5)
249    ["value2":"object_class":private]=>
250    int(10)
251    ["value3":protected]=>
252    int(20)
253    ["value4"]=>
254    int(30)
255    ["array_var"]=>
256    array(2) refcount(%d){
257      ["key1"]=>
258      int(1)
259      ["key2 "]=>
260      int(3)
261    }
262    ["object_class1"]=>
263    object(object_class)#%d (6) refcount(%d){
264      ["value1"]=>
265      int(5)
266      ["value2":"object_class":private]=>
267      int(10)
268      ["value3":protected]=>
269      int(20)
270      ["value4"]=>
271      int(30)
272      ["array_var"]=>
273      array(2) refcount(%d){
274        ["key1"]=>
275        int(1)
276        ["key2 "]=>
277        int(3)
278      }
279      ["object_class1"]=>
280      *RECURSION*
281    }
282  }
283  ["class_object4":protected]=>
284  object(object_class)#%d (6) refcount(%d){
285    ["value1"]=>
286    int(5)
287    ["value2":"object_class":private]=>
288    int(10)
289    ["value3":protected]=>
290    int(20)
291    ["value4"]=>
292    int(30)
293    ["array_var"]=>
294    array(2) refcount(%d){
295      ["key1"]=>
296      int(1)
297      ["key2 "]=>
298      int(3)
299    }
300    ["object_class1"]=>
301    object(object_class)#%d (6) refcount(%d){
302      ["value1"]=>
303      int(5)
304      ["value2":"object_class":private]=>
305      int(10)
306      ["value3":protected]=>
307      int(20)
308      ["value4"]=>
309      int(30)
310      ["array_var"]=>
311      array(2) refcount(%d){
312        ["key1"]=>
313        int(1)
314        ["key2 "]=>
315        int(3)
316      }
317      ["object_class1"]=>
318      *RECURSION*
319    }
320  }
321  ["no_member_class_object"]=>
322  object(no_member_class)#%d (0) refcount(%d){
323  }
324  ["class_object5"]=>
325  object(contains_object_class)#%d (9) refcount(%d){
326    ["p"]=>
327    int(30)
328    ["p1":protected]=>
329    int(40)
330    ["p2":"contains_object_class":private]=>
331    int(50)
332    ["class_object1"]=>
333    object(object_class)#%d (6) refcount(%d){
334      ["value1"]=>
335      int(5)
336      ["value2":"object_class":private]=>
337      int(10)
338      ["value3":protected]=>
339      int(20)
340      ["value4"]=>
341      int(30)
342      ["array_var"]=>
343      array(2) refcount(%d){
344        ["key1"]=>
345        int(1)
346        ["key2 "]=>
347        int(3)
348      }
349      ["object_class1"]=>
350      object(object_class)#%d (6) refcount(%d){
351        ["value1"]=>
352        int(5)
353        ["value2":"object_class":private]=>
354        int(10)
355        ["value3":protected]=>
356        int(20)
357        ["value4"]=>
358        int(30)
359        ["array_var"]=>
360        array(2) refcount(%d){
361          ["key1"]=>
362          int(1)
363          ["key2 "]=>
364          int(3)
365        }
366        ["object_class1"]=>
367        *RECURSION*
368      }
369    }
370    ["class_object2"]=>
371    object(object_class)#%d (6) refcount(%d){
372      ["value1"]=>
373      int(5)
374      ["value2":"object_class":private]=>
375      int(10)
376      ["value3":protected]=>
377      int(20)
378      ["value4"]=>
379      int(30)
380      ["array_var"]=>
381      array(2) refcount(%d){
382        ["key1"]=>
383        int(1)
384        ["key2 "]=>
385        int(3)
386      }
387      ["object_class1"]=>
388      object(object_class)#%d (6) refcount(%d){
389        ["value1"]=>
390        int(5)
391        ["value2":"object_class":private]=>
392        int(10)
393        ["value3":protected]=>
394        int(20)
395        ["value4"]=>
396        int(30)
397        ["array_var"]=>
398        array(2) refcount(%d){
399          ["key1"]=>
400          int(1)
401          ["key2 "]=>
402          int(3)
403        }
404        ["object_class1"]=>
405        *RECURSION*
406      }
407    }
408    ["class_object3":"contains_object_class":private]=>
409    object(object_class)#%d (6) refcount(%d){
410      ["value1"]=>
411      int(5)
412      ["value2":"object_class":private]=>
413      int(10)
414      ["value3":protected]=>
415      int(20)
416      ["value4"]=>
417      int(30)
418      ["array_var"]=>
419      array(2) refcount(%d){
420        ["key1"]=>
421        int(1)
422        ["key2 "]=>
423        int(3)
424      }
425      ["object_class1"]=>
426      object(object_class)#%d (6) refcount(%d){
427        ["value1"]=>
428        int(5)
429        ["value2":"object_class":private]=>
430        int(10)
431        ["value3":protected]=>
432        int(20)
433        ["value4"]=>
434        int(30)
435        ["array_var"]=>
436        array(2) refcount(%d){
437          ["key1"]=>
438          int(1)
439          ["key2 "]=>
440          int(3)
441        }
442        ["object_class1"]=>
443        *RECURSION*
444      }
445    }
446    ["class_object4":protected]=>
447    object(object_class)#%d (6) refcount(%d){
448      ["value1"]=>
449      int(5)
450      ["value2":"object_class":private]=>
451      int(10)
452      ["value3":protected]=>
453      int(20)
454      ["value4"]=>
455      int(30)
456      ["array_var"]=>
457      array(2) refcount(%d){
458        ["key1"]=>
459        int(1)
460        ["key2 "]=>
461        int(3)
462      }
463      ["object_class1"]=>
464      object(object_class)#%d (6) refcount(%d){
465        ["value1"]=>
466        int(5)
467        ["value2":"object_class":private]=>
468        int(10)
469        ["value3":protected]=>
470        int(20)
471        ["value4"]=>
472        int(30)
473        ["array_var"]=>
474        array(2) refcount(%d){
475          ["key1"]=>
476          int(1)
477          ["key2 "]=>
478          int(3)
479        }
480        ["object_class1"]=>
481        *RECURSION*
482      }
483    }
484    ["no_member_class_object"]=>
485    object(no_member_class)#%d (0) refcount(%d){
486    }
487    ["class_object5"]=>
488    *RECURSION*
489  }
490}
491-- Iteration 4 --
492object(object_class)#%d (6) refcount(%d){
493  ["value1"]=>
494  int(5)
495  ["value2":"object_class":private]=>
496  int(10)
497  ["value3":protected]=>
498  int(20)
499  ["value4"]=>
500  int(30)
501  ["array_var"]=>
502  array(2) refcount(%d){
503    ["key1"]=>
504    int(1)
505    ["key2 "]=>
506    int(3)
507  }
508  ["object_class1"]=>
509  object(object_class)#%d (6) refcount(%d){
510    ["value1"]=>
511    int(5)
512    ["value2":"object_class":private]=>
513    int(10)
514    ["value3":protected]=>
515    int(20)
516    ["value4"]=>
517    int(30)
518    ["array_var"]=>
519    array(2) refcount(%d){
520      ["key1"]=>
521      int(1)
522      ["key2 "]=>
523      int(3)
524    }
525    ["object_class1"]=>
526    *RECURSION*
527  }
528}
529-- Iteration 5 --
530object(object_class)#%d (6) refcount(%d){
531  ["value1"]=>
532  int(5)
533  ["value2":"object_class":private]=>
534  int(10)
535  ["value3":protected]=>
536  int(20)
537  ["value4"]=>
538  int(30)
539  ["array_var"]=>
540  array(2) refcount(%d){
541    ["key1"]=>
542    int(1)
543    ["key2 "]=>
544    int(3)
545  }
546  ["object_class1"]=>
547  object(object_class)#%d (6) refcount(%d){
548    ["value1"]=>
549    int(5)
550    ["value2":"object_class":private]=>
551    int(10)
552    ["value3":protected]=>
553    int(20)
554    ["value4"]=>
555    int(30)
556    ["array_var"]=>
557    array(2) refcount(%d){
558      ["key1"]=>
559      int(1)
560      ["key2 "]=>
561      int(3)
562    }
563    ["object_class1"]=>
564    *RECURSION*
565  }
566}
567-- Iteration 6 --
568object(no_member_class)#%d (0) refcount(%d){
569}
570-- Iteration 7 --
571NULL
572-- Iteration 8 --
573object(object_class)#%d (6) refcount(%d){
574  ["value1"]=>
575  int(5)
576  ["value2":"object_class":private]=>
577  int(10)
578  ["value3":protected]=>
579  int(20)
580  ["value4"]=>
581  int(30)
582  ["array_var"]=>
583  array(2) refcount(%d){
584    ["key1"]=>
585    int(1)
586    ["key2 "]=>
587    int(3)
588  }
589  ["object_class1"]=>
590  object(object_class)#%d (6) refcount(%d){
591    ["value1"]=>
592    int(5)
593    ["value2":"object_class":private]=>
594    int(10)
595    ["value3":protected]=>
596    int(20)
597    ["value4"]=>
598    int(30)
599    ["array_var"]=>
600    array(2) refcount(%d){
601      ["key1"]=>
602      int(1)
603      ["key2 "]=>
604      int(3)
605    }
606    ["object_class1"]=>
607    *RECURSION*
608  }
609}
610-- Iteration 9 --
611object(object_class)#%d (6) refcount(%d){
612  ["value1"]=>
613  int(5)
614  ["value2":"object_class":private]=>
615  int(10)
616  ["value3":protected]=>
617  int(20)
618  ["value4"]=>
619  int(30)
620  ["array_var"]=>
621  array(2) refcount(%d){
622    ["key1"]=>
623    int(1)
624    ["key2 "]=>
625    int(3)
626  }
627  ["object_class1"]=>
628  object(object_class)#%d (6) refcount(%d){
629    ["value1"]=>
630    int(5)
631    ["value2":"object_class":private]=>
632    int(10)
633    ["value3":protected]=>
634    int(20)
635    ["value4"]=>
636    int(30)
637    ["array_var"]=>
638    array(2) refcount(%d){
639      ["key1"]=>
640      int(1)
641      ["key2 "]=>
642      int(3)
643    }
644    ["object_class1"]=>
645    *RECURSION*
646  }
647}
648-- Iteration 10 --
649int(30)
650-- Iteration 11 --
651NULL
652
653-- Testing debug_zval_dump() on overwritten object variables --
654int(500)
655int(500)
656int(500)
657int(500)
658
659-- Testing debug_zval_dump() on objects having circular reference --
660object(object_class)#%d (7) refcount(%d){
661  ["value1"]=>
662  int(5)
663  ["value2":"object_class":private]=>
664  int(10)
665  ["value3":protected]=>
666  int(20)
667  ["value4"]=>
668  int(30)
669  ["array_var"]=>
670  array(2) refcount(%d){
671    ["key1"]=>
672    int(1)
673    ["key2 "]=>
674    int(3)
675  }
676  ["object_class1"]=>
677  object(object_class)#%d (7) refcount(%d){
678    ["value1"]=>
679    int(5)
680    ["value2":"object_class":private]=>
681    int(10)
682    ["value3":protected]=>
683    int(20)
684    ["value4"]=>
685    int(30)
686    ["array_var"]=>
687    array(2) refcount(%d){
688      ["key1"]=>
689      int(1)
690      ["key2 "]=>
691      int(3)
692    }
693    ["object_class1"]=>
694    *RECURSION*
695    ["obj"]=>
696    &object(object_class)#%d (7) refcount(%d){
697      ["value1"]=>
698      int(5)
699      ["value2":"object_class":private]=>
700      int(10)
701      ["value3":protected]=>
702      int(20)
703      ["value4"]=>
704      int(30)
705      ["array_var"]=>
706      array(2) refcount(%d){
707        ["key1"]=>
708        int(1)
709        ["key2 "]=>
710        int(3)
711      }
712      ["object_class1"]=>
713      object(object_class)#%d (7) refcount(%d){
714        ["value1"]=>
715        int(5)
716        ["value2":"object_class":private]=>
717        int(10)
718        ["value3":protected]=>
719        int(20)
720        ["value4"]=>
721        int(30)
722        ["array_var"]=>
723        array(2) refcount(%d){
724          ["key1"]=>
725          int(1)
726          ["key2 "]=>
727          int(3)
728        }
729        ["object_class1"]=>
730        *RECURSION*
731        ["obj"]=>
732        *RECURSION*
733      }
734      ["obj"]=>
735      *RECURSION*
736    }
737  }
738  ["obj"]=>
739  &object(object_class)#%d (7) refcount(%d){
740    ["value1"]=>
741    int(5)
742    ["value2":"object_class":private]=>
743    int(10)
744    ["value3":protected]=>
745    int(20)
746    ["value4"]=>
747    int(30)
748    ["array_var"]=>
749    array(2) refcount(%d){
750      ["key1"]=>
751      int(1)
752      ["key2 "]=>
753      int(3)
754    }
755    ["object_class1"]=>
756    object(object_class)#%d (7) refcount(%d){
757      ["value1"]=>
758      int(5)
759      ["value2":"object_class":private]=>
760      int(10)
761      ["value3":protected]=>
762      int(20)
763      ["value4"]=>
764      int(30)
765      ["array_var"]=>
766      array(2) refcount(%d){
767        ["key1"]=>
768        int(1)
769        ["key2 "]=>
770        int(3)
771      }
772      ["object_class1"]=>
773      *RECURSION*
774      ["obj"]=>
775      &object(object_class)#%d (7) refcount(%d){
776        ["value1"]=>
777        int(5)
778        ["value2":"object_class":private]=>
779        int(10)
780        ["value3":protected]=>
781        int(20)
782        ["value4"]=>
783        int(30)
784        ["array_var"]=>
785        array(2) refcount(%d){
786          ["key1"]=>
787          int(1)
788          ["key2 "]=>
789          int(3)
790        }
791        ["object_class1"]=>
792        *RECURSION*
793        ["obj"]=>
794        *RECURSION*
795      }
796    }
797    ["obj"]=>
798    &object(object_class)#%d (7) refcount(%d){
799      ["value1"]=>
800      int(5)
801      ["value2":"object_class":private]=>
802      int(10)
803      ["value3":protected]=>
804      int(20)
805      ["value4"]=>
806      int(30)
807      ["array_var"]=>
808      array(2) refcount(%d){
809        ["key1"]=>
810        int(1)
811        ["key2 "]=>
812        int(3)
813      }
814      ["object_class1"]=>
815      *RECURSION*
816      ["obj"]=>
817      &object(object_class)#%d (7) refcount(%d){
818        ["value1"]=>
819        int(5)
820        ["value2":"object_class":private]=>
821        int(10)
822        ["value3":protected]=>
823        int(20)
824        ["value4"]=>
825        int(30)
826        ["array_var"]=>
827        array(2) refcount(%d){
828          ["key1"]=>
829          int(1)
830          ["key2 "]=>
831          int(3)
832        }
833        ["object_class1"]=>
834        *RECURSION*
835        ["obj"]=>
836        *RECURSION*
837      }
838    }
839  }
840}
841Done
842