1--TEST--
2Test debug_zval_dump() function : usage variations
3--INI--
4allow_call_time_pass_reference=1
5--FILE--
6<?php
7/* Prototype: void debug_zval_dump ( mixed $variable );
8   Description: Dumps a string representation of an internal zend value
9                to output.
10*/
11
12echo "*** Testing debug_zval_dump() on functions ***\n";
13echo "--- Variation 1: global variable inside a function ---\n";
14$global_var = 10;  //declaring global variable
15
16/* function to dump reference count of global variable,$global_var
17   and local variable,$local_var */
18function dump_globalvar( &$local_var ) {
19  global $global_var;
20  echo "\n-- Value of local variable inside dump_globalvar() --\n";
21  debug_zval_dump( $local_var );
22  echo "\n-- Value of global variable inside dump_globalvar() --\n";
23  debug_zval_dump( $global_var );
24}
25/* dump value and reference count of $global_var using debug_zval_dump() */
26echo "\n-- Value of global variable, before calling dump_globalvar() --\n";
27debug_zval_dump( $global_var );
28
29/* calling function dump_globalvar() to check the reference count of local
30   and global variables inside the function */
31dump_globalvar( $global_var );
32
33/* dump value and reference count of $global_var after exiting function
34   dump_globalvar();
35   expected: reference count of $global_var should remain the same as
36             before calling dump_globalvar() function */
37echo "\n-- Value of global variable, after exiting dump_globalvar() --\n";
38debug_zval_dump( $global_var );
39
40echo "\n--- Variation 2: one variable references another ---\n";
41$first_var = 10;
42/* dump value and reference count of $first_var */
43echo "\n-- Value of \$first_var: --\n";
44debug_zval_dump($first_var);
45
46/* $ref_first_var references $first_var */
47$ref_first_var = &$var_1;
48
49echo "\n-- Value of \$ref_first_var --\n";
50debug_zval_dump($ref_first_var);
51echo "\n-- Value of \$first_var --\n";
52debug_zval_dump($first_var);
53
54unset($ref_first_var);
55
56/* dump value and reference count of $first_var, $ref_first_var
57   here $ref_first_var is unset */
58echo "\n-- Value of \$ref_first_var --\n";
59debug_zval_dump($ref_first_var);
60echo "\n-- Value of \$first_var --\n";
61debug_zval_dump($first_var);
62
63echo "\n--- Variation 3: multiple references of variables ---\n";
64$var_1 = 10;
65$var_2 = &$var_1;
66$var_3 = &$var_2;
67echo "\n-- Value of \$var_1: (before referencing) --\n";
68debug_zval_dump($var_1);
69echo "\n-- Value of \$var_2: (referencing var_1) --\n";
70debug_zval_dump($var_2);
71echo "\n-- Value of \$var_3: (referencing var_2) --\n";
72debug_zval_dump($var_3);
73
74/* unsetting $var_3 */
75unset($var_3);
76echo "\n-- Value of \$var_3: (after unsetting var_3) --\n";
77debug_zval_dump($var_3);
78echo "\n-- Value of \$var_2: --\n";
79debug_zval_dump($var_2);
80echo "\n-- Value of \$var_3: --\n";
81debug_zval_dump($var_1);
82
83/* unsetting $var_1 */
84unset($var_1);
85echo "\n-- Value of \$var_1: (after unsetting variable_1) --\n";
86debug_zval_dump($var_1);
87echo "\n-- Value of \$var_2: --\n";
88debug_zval_dump($var_2);
89
90echo "\n*** Testing debug_zval_dump() on miscelleneous input arguments ***\n";
91/* unset a variable */
92$unset_var = 10.5;
93unset($unset_var);
94
95$misc_values = array (
96  /* nulls */
97  NULL,
98  null,
99
100  /* unset variable */
101  @$unset_var,
102
103  /* undefined variable */
104  @$undef_var,
105
106 /* mixed types */
107  @TRUE123,
108  "123string",
109  "string123",
110  "NULLstring"
111);
112/* loop to display the variables and its reference count using
113    debug_zval_dump() */
114$counter = 1;
115foreach( $misc_values as $value ) {
116  echo "-- Iteration $counter --\n";
117  debug_zval_dump( $value );
118  debug_zval_dump( &$value );
119  $counter++;
120}
121
122echo "Done\n";
123?>
124
125--EXPECTF--
126*** Testing debug_zval_dump() on functions ***
127--- Variation 1: global variable inside a function ---
128
129-- Value of global variable, before calling dump_globalvar() --
130long(10) refcount(2)
131
132-- Value of local variable inside dump_globalvar() --
133long(10) refcount(1)
134
135-- Value of global variable inside dump_globalvar() --
136long(10) refcount(1)
137
138-- Value of global variable, after exiting dump_globalvar() --
139long(10) refcount(2)
140
141--- Variation 2: one variable references another ---
142
143-- Value of $first_var: --
144long(10) refcount(2)
145
146-- Value of $ref_first_var --
147NULL refcount(1)
148
149-- Value of $first_var --
150long(10) refcount(2)
151
152-- Value of $ref_first_var --
153
154Notice: Undefined variable: ref_first_var in %s on line %d
155NULL refcount(1)
156
157-- Value of $first_var --
158long(10) refcount(2)
159
160--- Variation 3: multiple references of variables ---
161
162-- Value of $var_1: (before referencing) --
163long(10) refcount(1)
164
165-- Value of $var_2: (referencing var_1) --
166long(10) refcount(1)
167
168-- Value of $var_3: (referencing var_2) --
169long(10) refcount(1)
170
171-- Value of $var_3: (after unsetting var_3) --
172
173Notice: Undefined variable: var_3 in %s on line %d
174NULL refcount(1)
175
176-- Value of $var_2: --
177long(10) refcount(1)
178
179-- Value of $var_3: --
180long(10) refcount(1)
181
182-- Value of $var_1: (after unsetting variable_1) --
183
184Notice: Undefined variable: var_1 in %s on line %d
185NULL refcount(1)
186
187-- Value of $var_2: --
188long(10) refcount(2)
189
190*** Testing debug_zval_dump() on miscelleneous input arguments ***
191-- Iteration 1 --
192NULL refcount(3)
193&NULL refcount(2)
194-- Iteration 2 --
195NULL refcount(3)
196&NULL refcount(2)
197-- Iteration 3 --
198NULL refcount(1)
199&NULL refcount(2)
200-- Iteration 4 --
201NULL refcount(1)
202&NULL refcount(2)
203-- Iteration 5 --
204string(7) "TRUE123" refcount(3)
205&string(7) "TRUE123" refcount(2)
206-- Iteration 6 --
207string(9) "123string" refcount(3)
208&string(9) "123string" refcount(2)
209-- Iteration 7 --
210string(9) "string123" refcount(3)
211&string(9) "string123" refcount(2)
212-- Iteration 8 --
213string(10) "NULLstring" refcount(3)
214&string(10) "NULLstring" refcount(2)
215Done
216