1--TEST--
2Test array_multisort() function : usage variation
3--FILE--
4<?php
5/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
6 * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL
7 * Source code: ext/standard/array.c
8 * Alias to functions:
9 */
10
11echo "*** Testing array_multisort() : 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$ar1 = array(1, 2);
24$ar2 = array(1, 2);
25
26//get an unset variable
27$unset_var = 10;
28unset ($unset_var);
29
30// define some classes
31class classWithToString
32{
33	public function __toString() {
34		return "Class A object";
35	}
36}
37
38class classWithoutToString
39{
40}
41
42// heredoc string
43$heredoc = <<<EOT
44hello world
45EOT;
46
47// add arrays
48$index_array = array (1, 2, 3);
49$assoc_array = array ('one' => 1, 'two' => 2);
50
51//array of values to iterate over
52$inputs = array(
53
54      // int data
55      'int 0' => 0,
56      'int 1' => 1,
57      'int 12345' => 12345,
58      'int -12345' => -2345,
59
60      // float data
61      'float 10.5' => 10.5,
62      'float -10.5' => -10.5,
63      'float 12.3456789000e10' => 12.3456789000e10,
64      'float -12.3456789000e10' => -12.3456789000e10,
65      'float .5' => .5,
66
67      // array data
68      'empty array' => array(),
69      'int indexed array' => $index_array,
70      'associative array' => $assoc_array,
71      'nested arrays' => array('foo', $index_array, $assoc_array),
72
73      // null data
74      'uppercase NULL' => NULL,
75      'lowercase null' => null,
76
77      // boolean data
78      'lowercase true' => true,
79      'lowercase false' =>false,
80      'uppercase TRUE' =>TRUE,
81      'uppercase FALSE' =>FALSE,
82
83      // empty data
84      'empty string DQ' => "",
85      'empty string SQ' => '',
86
87      // string data
88      'string DQ' => "string",
89      'string SQ' => 'string',
90      'mixed case string' => "sTrInG",
91      'heredoc' => $heredoc,
92
93      // object data
94      'instance of classWithToString' => new classWithToString(),
95      'instance of classWithoutToString' => new classWithoutToString(),
96
97      // undefined data
98      'undefined var' => @$undefined_var,
99
100      // unset data
101      'unset var' => @$unset_var,
102);
103
104// loop through each element of the array for SORT_REGULAR|SORT_NUMERIC|SORT_STRING]]
105
106foreach($inputs as $key =>$value) {
107      echo "\n--$key--\n";
108      var_dump( array_multisort($ar1, $value) );
109};
110
111?>
112===DONE===
113--EXPECTF--
114*** Testing array_multisort() : usage variation ***
115
116--int 0--
117bool(true)
118
119--int 1--
120bool(true)
121
122--int 12345--
123Error: 2 - array_multisort(): Argument #2 is an unknown sort flag, %sarray_multisort_variation2.php(%d)
124bool(false)
125
126--int -12345--
127Error: 2 - array_multisort(): Argument #2 is an unknown sort flag, %sarray_multisort_variation2.php(%d)
128bool(false)
129
130--float 10.5--
131Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
132bool(false)
133
134--float -10.5--
135Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
136bool(false)
137
138--float 12.3456789000e10--
139Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
140bool(false)
141
142--float -12.3456789000e10--
143Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
144bool(false)
145
146--float .5--
147Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
148bool(false)
149
150--empty array--
151Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d)
152bool(false)
153
154--int indexed array--
155Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d)
156bool(false)
157
158--associative array--
159bool(true)
160
161--nested arrays--
162Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d)
163bool(false)
164
165--uppercase NULL--
166Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
167bool(false)
168
169--lowercase null--
170Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
171bool(false)
172
173--lowercase true--
174Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
175bool(false)
176
177--lowercase false--
178Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
179bool(false)
180
181--uppercase TRUE--
182Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
183bool(false)
184
185--uppercase FALSE--
186Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
187bool(false)
188
189--empty string DQ--
190Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
191bool(false)
192
193--empty string SQ--
194Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
195bool(false)
196
197--string DQ--
198Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
199bool(false)
200
201--string SQ--
202Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
203bool(false)
204
205--mixed case string--
206Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
207bool(false)
208
209--heredoc--
210Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
211bool(false)
212
213--instance of classWithToString--
214Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
215bool(false)
216
217--instance of classWithoutToString--
218Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
219bool(false)
220
221--undefined var--
222Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
223bool(false)
224
225--unset var--
226Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d)
227bool(false)
228===DONE===
229