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