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