1--TEST--
2Test call_user_func_array() function : second 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)
23function test_func() {
24}
25$function_name = 'test_func';
26
27//get an unset variable
28$unset_var = 10;
29unset ($unset_var);
30
31// define some classes
32class classWithToString
33{
34	public function __toString() {
35		return "Class A object";
36	}
37}
38
39class classWithoutToString
40{
41}
42
43// heredoc string
44$heredoc = <<<EOT
45hello world
46EOT;
47
48// add arrays
49$index_array = array (1, 2, 3);
50$assoc_array = array ('one' => 1, 'two' => 2);
51
52//array of values to iterate over
53$inputs = array(
54
55      // int data
56      'int 0' => 0,
57      'int 1' => 1,
58      'int 12345' => 12345,
59      'int -12345' => -2345,
60
61      // float data
62      'float 10.5' => 10.5,
63      'float -10.5' => -10.5,
64      'float 12.3456789000e10' => 12.3456789000e10,
65      'float -12.3456789000e10' => -12.3456789000e10,
66      'float .5' => .5,
67
68      // null data
69      'uppercase NULL' => NULL,
70      'lowercase null' => null,
71
72      // boolean data
73      'lowercase true' => true,
74      'lowercase false' =>false,
75      'uppercase TRUE' =>TRUE,
76      'uppercase FALSE' =>FALSE,
77
78      // empty data
79      'empty string DQ' => "",
80      'empty string SQ' => '',
81
82      // string data
83      'string DQ' => "string",
84      'string SQ' => 'string',
85      'mixed case string' => "sTrInG",
86      'heredoc' => $heredoc,
87
88      // object data
89      'instance of classWithToString' => new classWithToString(),
90      'instance of classWithoutToString' => new classWithoutToString(),
91
92      // undefined data
93      'undefined var' => @$undefined_var,
94
95      // unset data
96      'unset var' => @$unset_var,
97);
98
99// loop through each element of the array for parameters
100
101foreach($inputs as $key =>$value) {
102      echo "\n--$key--\n";
103      var_dump( call_user_func_array($function_name, $value) );
104};
105
106?>
107===DONE===
108--EXPECTF--
109*** Testing call_user_func_array() : usage variation ***
110
111--int 0--
112Error: 2 - call_user_func_array() expects parameter 2 to be array, integer given, %s(%d)
113NULL
114
115--int 1--
116Error: 2 - call_user_func_array() expects parameter 2 to be array, integer given, %s(%d)
117NULL
118
119--int 12345--
120Error: 2 - call_user_func_array() expects parameter 2 to be array, integer given, %s(%d)
121NULL
122
123--int -12345--
124Error: 2 - call_user_func_array() expects parameter 2 to be array, integer given, %s(%d)
125NULL
126
127--float 10.5--
128Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
129NULL
130
131--float -10.5--
132Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
133NULL
134
135--float 12.3456789000e10--
136Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
137NULL
138
139--float -12.3456789000e10--
140Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
141NULL
142
143--float .5--
144Error: 2 - call_user_func_array() expects parameter 2 to be array, double given, %s(%d)
145NULL
146
147--uppercase NULL--
148Error: 2 - call_user_func_array() expects parameter 2 to be array, null given, %s(%d)
149NULL
150
151--lowercase null--
152Error: 2 - call_user_func_array() expects parameter 2 to be array, null given, %s(%d)
153NULL
154
155--lowercase true--
156Error: 2 - call_user_func_array() expects parameter 2 to be array, boolean given, %s(%d)
157NULL
158
159--lowercase false--
160Error: 2 - call_user_func_array() expects parameter 2 to be array, boolean given, %s(%d)
161NULL
162
163--uppercase TRUE--
164Error: 2 - call_user_func_array() expects parameter 2 to be array, boolean given, %s(%d)
165NULL
166
167--uppercase FALSE--
168Error: 2 - call_user_func_array() expects parameter 2 to be array, boolean given, %s(%d)
169NULL
170
171--empty string DQ--
172Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
173NULL
174
175--empty string SQ--
176Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
177NULL
178
179--string DQ--
180Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
181NULL
182
183--string SQ--
184Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
185NULL
186
187--mixed case string--
188Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
189NULL
190
191--heredoc--
192Error: 2 - call_user_func_array() expects parameter 2 to be array, string given, %s(%d)
193NULL
194
195--instance of classWithToString--
196Error: 2 - call_user_func_array() expects parameter 2 to be array, object given, %s(%d)
197NULL
198
199--instance of classWithoutToString--
200Error: 2 - call_user_func_array() expects parameter 2 to be array, object given, %s(%d)
201NULL
202
203--undefined var--
204Error: 2 - call_user_func_array() expects parameter 2 to be array, null given, %s(%d)
205NULL
206
207--unset var--
208Error: 2 - call_user_func_array() expects parameter 2 to be array, null given, %s(%d)
209NULL
210===DONE===
211