1--TEST--
2Test array_multisort() function : usage variation
3--FILE--
4<?php
5echo "*** Testing array_multisort() : usage variation ***\n";
6
7// Define error handler
8function test_error_handler($err_no, $err_msg, $filename, $linenum) {
9    if (error_reporting() & $err_no) {
10        // report non-silenced errors
11        echo "Error: $err_no - $err_msg, $filename($linenum)\n";
12    }
13}
14set_error_handler('test_error_handler');
15
16// Initialise function arguments not being substituted (if any)
17$ar1 = array(1, 2);
18
19//get an unset variable
20$unset_var = 10;
21unset ($unset_var);
22
23// define some classes
24class classWithToString
25{
26    public function __toString() {
27        return "Class A object";
28    }
29}
30
31class classWithoutToString
32{
33}
34
35// heredoc string
36$heredoc = <<<EOT
37hello world
38EOT;
39
40// add arrays
41$index_array = array (1, 2, 3);
42$assoc_array = array ('one' => 1, 'two' => 2);
43
44//array of values to iterate over
45$inputs = array(
46
47      // int data
48      'int 0' => 0,
49      'int 1' => 1,
50      'int 12345' => 12345,
51      'int -12345' => -2345,
52
53      // float data
54      'float 10.5' => 10.5,
55      'float -10.5' => -10.5,
56      'float 12.3456789000e10' => 12.3456789000e10,
57      'float -12.3456789000e10' => -12.3456789000e10,
58      'float .5' => .5,
59
60      // null data
61      'uppercase NULL' => NULL,
62      'lowercase null' => null,
63
64      // boolean data
65      'lowercase true' => true,
66      'lowercase false' =>false,
67      'uppercase TRUE' =>TRUE,
68      'uppercase FALSE' =>FALSE,
69
70      // empty data
71      'empty string DQ' => "",
72      'empty string SQ' => '',
73
74      // string data
75      'string DQ' => "string",
76      'string SQ' => 'string',
77      'mixed case string' => "sTrInG",
78      'heredoc' => $heredoc,
79
80      // object data
81      'instance of classWithToString' => new classWithToString(),
82      'instance of classWithoutToString' => new classWithoutToString(),
83
84      // undefined data
85      'undefined var' => @$undefined_var,
86
87      // unset data
88      'unset var' => @$unset_var,
89);
90
91// loop through each element of the array for ar2
92foreach($inputs as $key =>$value) {
93    echo "\n--$key--\n";
94    try {
95        var_dump( array_multisort($ar1, SORT_REGULAR, $value) );
96    } catch (\ValueError | \TypeError $e) {
97        echo $e->getMessage() . "\n";
98    }
99};
100
101?>
102--EXPECT--
103*** Testing array_multisort() : usage variation ***
104
105--int 0--
106array_multisort(): Argument #3 must be an array or a sort flag that has not already been specified
107
108--int 1--
109array_multisort(): Argument #3 must be an array or a sort flag that has not already been specified
110
111--int 12345--
112array_multisort(): Argument #3 must be a valid sort flag
113
114--int -12345--
115array_multisort(): Argument #3 must be a valid sort flag
116
117--float 10.5--
118array_multisort(): Argument #3 must be an array or a sort flag
119
120--float -10.5--
121array_multisort(): Argument #3 must be an array or a sort flag
122
123--float 12.3456789000e10--
124array_multisort(): Argument #3 must be an array or a sort flag
125
126--float -12.3456789000e10--
127array_multisort(): Argument #3 must be an array or a sort flag
128
129--float .5--
130array_multisort(): Argument #3 must be an array or a sort flag
131
132--uppercase NULL--
133array_multisort(): Argument #3 must be an array or a sort flag
134
135--lowercase null--
136array_multisort(): Argument #3 must be an array or a sort flag
137
138--lowercase true--
139array_multisort(): Argument #3 must be an array or a sort flag
140
141--lowercase false--
142array_multisort(): Argument #3 must be an array or a sort flag
143
144--uppercase TRUE--
145array_multisort(): Argument #3 must be an array or a sort flag
146
147--uppercase FALSE--
148array_multisort(): Argument #3 must be an array or a sort flag
149
150--empty string DQ--
151array_multisort(): Argument #3 must be an array or a sort flag
152
153--empty string SQ--
154array_multisort(): Argument #3 must be an array or a sort flag
155
156--string DQ--
157array_multisort(): Argument #3 must be an array or a sort flag
158
159--string SQ--
160array_multisort(): Argument #3 must be an array or a sort flag
161
162--mixed case string--
163array_multisort(): Argument #3 must be an array or a sort flag
164
165--heredoc--
166array_multisort(): Argument #3 must be an array or a sort flag
167
168--instance of classWithToString--
169array_multisort(): Argument #3 must be an array or a sort flag
170
171--instance of classWithoutToString--
172array_multisort(): Argument #3 must be an array or a sort flag
173
174--undefined var--
175array_multisort(): Argument #3 must be an array or a sort flag
176
177--unset var--
178array_multisort(): Argument #3 must be an array or a sort flag
179