Return to get_class_vars_variation1.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / class_object |
1.1 misho 1: --TEST-- 2: Test get_class_vars() function : usage variation 3: --FILE-- 4: <?php 5: /* Prototype : array get_class_vars(string class_name) 6: * Description: Returns an array of default properties of the class. 7: * Source code: Zend/zend_builtin_functions.c 8: * Alias to functions: 9: */ 10: 11: echo "*** Testing get_class_vars() : usage variation ***\n"; 12: 13: //get an unset variable 14: $unset_var = 10; 15: unset ($unset_var); 16: 17: // define some classes 18: class classWithToString 19: { 20: public function __toString() { 21: return "Class A object"; 22: } 23: } 24: 25: class classWithoutToString 26: { 27: } 28: 29: // heredoc string 30: $heredoc = <<<EOT 31: hello world 32: EOT; 33: 34: // add arrays 35: $index_array = array (1, 2, 3); 36: $assoc_array = array ('one' => 1, 'two' => 2); 37: 38: //array of values to iterate over 39: $inputs = array( 40: 41: // int data 42: 'int 0' => 0, 43: 'int 1' => 1, 44: 'int 12345' => 12345, 45: 'int -12345' => -2345, 46: 47: // float data 48: 'float 10.5' => 10.5, 49: 'float -10.5' => -10.5, 50: 'float 12.3456789000e10' => 12.3456789000e10, 51: 'float -12.3456789000e10' => -12.3456789000e10, 52: 'float .5' => .5, 53: 54: // array data 55: 'empty array' => array(), 56: 'int indexed array' => $index_array, 57: 'associative array' => $assoc_array, 58: 'nested arrays' => array('foo', $index_array, $assoc_array), 59: 60: // null data 61: 'uppercase NULL' => NULL, 62: 'lowercase null' => null, 63: 64: // boolean data 65: 'lowercase true' => true, 66: 'lowercase false' =>false, 67: 'uppercase TRUE' =>TRUE, 68: 'uppercase FALSE' =>FALSE, 69: 70: // empty data 71: 'empty string DQ' => "", 72: 'empty string SQ' => '', 73: 74: // object data 75: 'instance of classWithToString' => new classWithToString(), 76: 'instance of classWithoutToString' => new classWithoutToString(), 77: 78: // undefined data 79: 'undefined var' => @$undefined_var, 80: 81: // unset data 82: 'unset var' => @$unset_var, 83: ); 84: 85: // loop through each element of the array for method_name 86: 87: foreach($inputs as $key =>$value) { 88: echo "\n--$key--\n"; 89: var_dump( get_class_vars($value) ); 90: }; 91: 92: ?> 93: ===DONE=== 94: --EXPECTF-- 95: *** Testing get_class_vars() : usage variation *** 96: 97: --int 0-- 98: bool(false) 99: 100: --int 1-- 101: bool(false) 102: 103: --int 12345-- 104: bool(false) 105: 106: --int -12345-- 107: bool(false) 108: 109: --float 10.5-- 110: bool(false) 111: 112: --float -10.5-- 113: bool(false) 114: 115: --float 12.3456789000e10-- 116: bool(false) 117: 118: --float -12.3456789000e10-- 119: bool(false) 120: 121: --float .5-- 122: bool(false) 123: 124: --empty array-- 125: 126: Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d 127: NULL 128: 129: --int indexed array-- 130: 131: Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d 132: NULL 133: 134: --associative array-- 135: 136: Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d 137: NULL 138: 139: --nested arrays-- 140: 141: Warning: get_class_vars() expects parameter 1 to be string, array given in %sget_class_vars_variation1.php on line %d 142: NULL 143: 144: --uppercase NULL-- 145: bool(false) 146: 147: --lowercase null-- 148: bool(false) 149: 150: --lowercase true-- 151: bool(false) 152: 153: --lowercase false-- 154: bool(false) 155: 156: --uppercase TRUE-- 157: bool(false) 158: 159: --uppercase FALSE-- 160: bool(false) 161: 162: --empty string DQ-- 163: bool(false) 164: 165: --empty string SQ-- 166: bool(false) 167: 168: --instance of classWithToString-- 169: bool(false) 170: 171: --instance of classWithoutToString-- 172: 173: Warning: get_class_vars() expects parameter 1 to be string, object given in %sget_class_vars_variation1.php on line %d 174: NULL 175: 176: --undefined var-- 177: bool(false) 178: 179: --unset var-- 180: bool(false) 181: ===DONE===