1--TEST-- 2Test get_defined_vars() function 3--FILE-- 4<?php 5echo "Simple testcase for get_defined_vars() function\n\n"; 6 7function f1() { 8 echo "\n-- Function f1() called --\n"; 9 $vars = get_defined_vars(); 10 11 if (count($vars) != 0) { 12 echo "TEST FAILED\n"; 13 } 14 15 echo "\n-- ..define some local variables --\n"; 16 $i = 123; 17 $f = 123.456; 18 $b = false; 19 $s = "Hello World"; 20 $arr = array(1,2,3,4); 21 var_dump( get_defined_vars() ); 22 f2(); 23} 24 25function f2() { 26 echo "\n -- Function f2() called --\n"; 27 $vars= get_defined_vars(); 28 29 if (count($vars) != 0) { 30 echo "TEST FAILED\n"; 31 } 32 33 echo "\n-- ...define some variables --\n"; 34 $i = 456; 35 $f = 456.678; 36 $b = true; 37 $s = "Goodnight"; 38 $arr = array("foo", "bar"); 39 var_dump( get_defined_vars() ); 40 41 echo "\n-- ...define some more variables --\n"; 42 $i1 = 456; 43 $f1 = 456.678; 44 $b1 = true; 45 var_dump( get_defined_vars() ); 46 47} 48 49echo "\n-- Get variables at global scope --\n"; 50$vars = get_defined_vars(); 51 52if (count($vars) == 0) { 53 echo "TEST FAILED - Global variables missing at global scope\n"; 54} 55 56// call a function 57f1(); 58 59?> 60--EXPECT-- 61Simple testcase for get_defined_vars() function 62 63 64-- Get variables at global scope -- 65 66-- Function f1() called -- 67 68-- ..define some local variables -- 69array(6) { 70 ["vars"]=> 71 array(0) { 72 } 73 ["i"]=> 74 int(123) 75 ["f"]=> 76 float(123.456) 77 ["b"]=> 78 bool(false) 79 ["s"]=> 80 string(11) "Hello World" 81 ["arr"]=> 82 array(4) { 83 [0]=> 84 int(1) 85 [1]=> 86 int(2) 87 [2]=> 88 int(3) 89 [3]=> 90 int(4) 91 } 92} 93 94 -- Function f2() called -- 95 96-- ...define some variables -- 97array(6) { 98 ["vars"]=> 99 array(0) { 100 } 101 ["i"]=> 102 int(456) 103 ["f"]=> 104 float(456.678) 105 ["b"]=> 106 bool(true) 107 ["s"]=> 108 string(9) "Goodnight" 109 ["arr"]=> 110 array(2) { 111 [0]=> 112 string(3) "foo" 113 [1]=> 114 string(3) "bar" 115 } 116} 117 118-- ...define some more variables -- 119array(9) { 120 ["vars"]=> 121 array(0) { 122 } 123 ["i"]=> 124 int(456) 125 ["f"]=> 126 float(456.678) 127 ["b"]=> 128 bool(true) 129 ["s"]=> 130 string(9) "Goodnight" 131 ["arr"]=> 132 array(2) { 133 [0]=> 134 string(3) "foo" 135 [1]=> 136 string(3) "bar" 137 } 138 ["i1"]=> 139 int(456) 140 ["f1"]=> 141 float(456.678) 142 ["b1"]=> 143 bool(true) 144} 145