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