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