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 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() -- 127int(10) 128 129-- Value of local variable inside dump_globalvar() -- 130int(10) 131 132-- Value of global variable inside dump_globalvar() -- 133int(10) 134 135-- Value of global variable, after exiting dump_globalvar() -- 136int(10) 137 138--- Variation 2: one variable references another --- 139 140-- Value of $first_var: -- 141int(10) 142 143-- Value of $ref_first_var -- 144NULL 145 146-- Value of $first_var -- 147int(10) 148 149-- Value of $ref_first_var -- 150 151Notice: Undefined variable: ref_first_var in %s on line %d 152NULL 153 154-- Value of $first_var -- 155int(10) 156 157--- Variation 3: multiple references of variables --- 158 159-- Value of $var_1: (before referencing) -- 160int(10) 161 162-- Value of $var_2: (referencing var_1) -- 163int(10) 164 165-- Value of $var_3: (referencing var_2) -- 166int(10) 167 168-- Value of $var_3: (after unsetting var_3) -- 169 170Notice: Undefined variable: var_3 in %s on line %d 171NULL 172 173-- Value of $var_2: -- 174int(10) 175 176-- Value of $var_3: -- 177int(10) 178 179-- Value of $var_1: (after unsetting variable_1) -- 180 181Notice: Undefined variable: var_1 in %s on line %d 182NULL 183 184-- Value of $var_2: -- 185int(10) 186 187*** Testing debug_zval_dump() on miscelleneous input arguments *** 188-- Iteration 1 -- 189NULL 190-- Iteration 2 -- 191NULL 192-- Iteration 3 -- 193NULL 194-- Iteration 4 -- 195NULL 196-- Iteration 5 -- 197string(7) "TRUE123" refcount(%d) 198-- Iteration 6 -- 199string(9) "123string" refcount(%d) 200-- Iteration 7 -- 201string(9) "string123" refcount(%d) 202-- Iteration 8 -- 203string(10) "NULLstring" refcount(%d) 204Done 205