1--TEST-- 2Test 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 10echo "*** Testing debug_zval_dump() on functions ***\n"; 11echo "--- 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 */ 16function 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() */ 24echo "\n-- Value of global variable, before calling dump_globalvar() --\n"; 25debug_zval_dump( $global_var ); 26 27/* calling function dump_globalvar() to check the reference count of local 28 and global variables inside the function */ 29dump_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 */ 35echo "\n-- Value of global variable, after exiting dump_globalvar() --\n"; 36debug_zval_dump( $global_var ); 37 38echo "\n--- Variation 2: one variable references another ---\n"; 39$first_var = 10; 40/* dump value and reference count of $first_var */ 41echo "\n-- Value of \$first_var: --\n"; 42debug_zval_dump($first_var); 43 44/* $ref_first_var references $first_var */ 45$ref_first_var = &$var_1; 46 47echo "\n-- Value of \$ref_first_var --\n"; 48debug_zval_dump($ref_first_var); 49echo "\n-- Value of \$first_var --\n"; 50debug_zval_dump($first_var); 51 52unset($ref_first_var); 53 54/* dump value and reference count of $first_var, $ref_first_var 55 here $ref_first_var is unset */ 56echo "\n-- Value of \$ref_first_var --\n"; 57debug_zval_dump($ref_first_var); 58echo "\n-- Value of \$first_var --\n"; 59debug_zval_dump($first_var); 60 61echo "\n--- Variation 3: multiple references of variables ---\n"; 62$var_1 = 10; 63$var_2 = &$var_1; 64$var_3 = &$var_2; 65echo "\n-- Value of \$var_1: (before referencing) --\n"; 66debug_zval_dump($var_1); 67echo "\n-- Value of \$var_2: (referencing var_1) --\n"; 68debug_zval_dump($var_2); 69echo "\n-- Value of \$var_3: (referencing var_2) --\n"; 70debug_zval_dump($var_3); 71 72/* unsetting $var_3 */ 73unset($var_3); 74echo "\n-- Value of \$var_3: (after unsetting var_3) --\n"; 75debug_zval_dump($var_3); 76echo "\n-- Value of \$var_2: --\n"; 77debug_zval_dump($var_2); 78echo "\n-- Value of \$var_3: --\n"; 79debug_zval_dump($var_1); 80 81/* unsetting $var_1 */ 82unset($var_1); 83echo "\n-- Value of \$var_1: (after unsetting variable_1) --\n"; 84debug_zval_dump($var_1); 85echo "\n-- Value of \$var_2: --\n"; 86debug_zval_dump($var_2); 87 88echo "\n*** Testing debug_zval_dump() on miscelleneous input arguments ***\n"; 89/* unset a variable */ 90$unset_var = 10.5; 91unset($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; 113foreach( $misc_values as $value ) { 114 echo "-- Iteration $counter --\n"; 115 debug_zval_dump( $value ); 116 $counter++; 117} 118 119echo "Done\n"; 120?> 121--EXPECTF-- 122*** Testing debug_zval_dump() on functions *** 123--- Variation 1: global variable inside a function --- 124 125-- Value of global variable, before calling dump_globalvar() -- 126int(10) 127 128-- Value of local variable inside dump_globalvar() -- 129int(10) 130 131-- Value of global variable inside dump_globalvar() -- 132int(10) 133 134-- Value of global variable, after exiting dump_globalvar() -- 135int(10) 136 137--- Variation 2: one variable references another --- 138 139-- Value of $first_var: -- 140int(10) 141 142-- Value of $ref_first_var -- 143NULL 144 145-- Value of $first_var -- 146int(10) 147 148-- Value of $ref_first_var -- 149 150Notice: Undefined variable: ref_first_var in %s on line %d 151NULL 152 153-- Value of $first_var -- 154int(10) 155 156--- Variation 3: multiple references of variables --- 157 158-- Value of $var_1: (before referencing) -- 159int(10) 160 161-- Value of $var_2: (referencing var_1) -- 162int(10) 163 164-- Value of $var_3: (referencing var_2) -- 165int(10) 166 167-- Value of $var_3: (after unsetting var_3) -- 168 169Notice: Undefined variable: var_3 in %s on line %d 170NULL 171 172-- Value of $var_2: -- 173int(10) 174 175-- Value of $var_3: -- 176int(10) 177 178-- Value of $var_1: (after unsetting variable_1) -- 179 180Notice: Undefined variable: var_1 in %s on line %d 181NULL 182 183-- Value of $var_2: -- 184int(10) 185 186*** Testing debug_zval_dump() on miscelleneous input arguments *** 187-- Iteration 1 -- 188NULL 189-- Iteration 2 -- 190NULL 191-- Iteration 3 -- 192NULL 193-- Iteration 4 -- 194NULL 195-- Iteration 5 -- 196string(7) "TRUE123" refcount(%d) 197-- Iteration 6 -- 198string(9) "123string" refcount(%d) 199-- Iteration 7 -- 200string(9) "string123" refcount(%d) 201-- Iteration 8 -- 202string(10) "NULLstring" refcount(%d) 203Done 204