1--TEST-- 2Test trait_exists() function : usage variations - unexpected types for argument 2 3--FILE-- 4<?php 5/* Prototype : proto bool trait_exists(string traitname [, bool autoload]) 6 * Description: Checks if the trait exists 7 * Source code: Zend/zend_builtin_functions.c 8 * Alias to functions: 9 */ 10 11spl_autoload_register(function ($traitName) { 12 echo "In autoload($traitName)\n"; 13}); 14 15function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { 16 echo "Error: $err_no - $err_msg, $filename($linenum)\n"; 17} 18set_error_handler('test_error_handler'); 19 20echo "*** Testing trait_exists() : usage variations ***\n"; 21 22// Initialise function arguments not being substituted (if any) 23$traitname = 'string_val'; 24 25//get an unset variable 26$unset_var = 10; 27unset ($unset_var); 28 29//array of values to iterate over 30$values = array( 31 32 // int data 33 0, 34 1, 35 12345, 36 -2345, 37 38 // float data 39 10.5, 40 -10.5, 41 10.1234567e10, 42 10.7654321E-10, 43 .5, 44 45 // array data 46 array(), 47 array(0), 48 array(1), 49 array(1, 2), 50 array('color' => 'red', 'item' => 'pen'), 51 52 // null data 53 NULL, 54 null, 55 56 // boolean data 57 true, 58 false, 59 TRUE, 60 FALSE, 61 62 // empty data 63 "", 64 '', 65 66 // string data 67 "string", 68 'string', 69 70 // object data 71 new stdclass(), 72 73 // undefined data 74 $undefined_var, 75 76 // unset data 77 $unset_var, 78); 79 80// loop through each element of the array for autoload 81 82foreach($values as $value) { 83 echo "\nArg value $value \n"; 84 var_dump( trait_exists($traitname, $value) ); 85}; 86 87echo "Done"; 88?> 89--EXPECTF-- 90*** Testing trait_exists() : usage variations *** 91Error: 8 - Undefined variable: undefined_var, %s(71) 92Error: 8 - Undefined variable: unset_var, %s(74) 93 94Arg value 0 95bool(false) 96 97Arg value 1 98In autoload(string_val) 99bool(false) 100 101Arg value 12345 102In autoload(string_val) 103bool(false) 104 105Arg value -2345 106In autoload(string_val) 107bool(false) 108 109Arg value 10.5 110In autoload(string_val) 111bool(false) 112 113Arg value -10.5 114In autoload(string_val) 115bool(false) 116 117Arg value 101234567000 118In autoload(string_val) 119bool(false) 120 121Arg value 1.07654321E-9 122In autoload(string_val) 123bool(false) 124 125Arg value 0.5 126In autoload(string_val) 127bool(false) 128Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) 129 130Arg value Array 131Error: 2 - trait_exists() expects parameter 2 to be bool, array given, %s(81) 132NULL 133Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) 134 135Arg value Array 136Error: 2 - trait_exists() expects parameter 2 to be bool, array given, %s(81) 137NULL 138Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) 139 140Arg value Array 141Error: 2 - trait_exists() expects parameter 2 to be bool, array given, %s(81) 142NULL 143Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) 144 145Arg value Array 146Error: 2 - trait_exists() expects parameter 2 to be bool, array given, %s(81) 147NULL 148Error: 8 - Array to string conversion, %strait_exists_variation_002.php(%d) 149 150Arg value Array 151Error: 2 - trait_exists() expects parameter 2 to be bool, array given, %s(81) 152NULL 153 154Arg value 155bool(false) 156 157Arg value 158bool(false) 159 160Arg value 1 161In autoload(string_val) 162bool(false) 163 164Arg value 165bool(false) 166 167Arg value 1 168In autoload(string_val) 169bool(false) 170 171Arg value 172bool(false) 173 174Arg value 175bool(false) 176 177Arg value 178bool(false) 179 180Arg value string 181In autoload(string_val) 182bool(false) 183 184Arg value string 185In autoload(string_val) 186bool(false) 187Error: 4096 - Object of class stdClass could not be converted to string, %s(80) 188 189Arg value 190Error: 2 - trait_exists() expects parameter 2 to be bool, object given, %s(81) 191NULL 192 193Arg value 194bool(false) 195 196Arg value 197bool(false) 198Done 199