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