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