1
0
mirror of https://github.com/php/php-src.git synced 2026-04-13 19:14:16 +02:00
Files
archived-php-src/ext/standard/tests/array/usort_variation1.phpt
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

237 lines
4.4 KiB
PHP

--TEST--
Test usort() function : usage variations - Pass different data types as $array_arg arg
--FILE--
<?php
/* Prototype : bool usort(array $array_arg, string $cmp_function)
* Description: Sort an array by values using a user-defined comparison function
* Source code: ext/standard/array.c
*/
/*
* Pass different data types as $array_arg argument to usort() to test behaviour
*/
echo "*** Testing usort() : usage variations ***\n";
// Initialise function arguments not being substituted
function cmp_function($value1, $value2)
{
if($value1 == $value2) {
return 0;
}
else if($value1 > $value2) {
return 1;
}
else {
return -1;
}
}
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// get a class
class classA
{
public function __toString() {
return "Class A object";
}
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// unexpected values to be passed to $array_arg argument
$inputs = array(
// int data
/*1*/ 0,
1,
12345,
-2345,
// float data
/*5*/ 10.5,
-10.5,
12.3456789000e10,
12.3456789000E-10,
.5,
// null data
/*10*/ NULL,
null,
// boolean data
/*12*/ true,
false,
TRUE,
FALSE,
// empty data
/*16*/ "",
'',
array(),
// string data
/*19*/ "string",
'string',
$heredoc,
// object data
/*22*/ new classA(),
// undefined data
/*23*/ @$undefined_var,
// unset data
/*24*/ @$unset_var,
// resource variable
/*25*/ $fp
);
// loop through each element of $inputs to check the behavior of usort()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
var_dump( usort($input, 'cmp_function') );
$iterator++;
};
//closing resource
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing usort() : usage variations ***
-- Iteration 1 --
Warning: usort() expects parameter 1 to be array, int given in %s on line %d
NULL
-- Iteration 2 --
Warning: usort() expects parameter 1 to be array, int given in %s on line %d
NULL
-- Iteration 3 --
Warning: usort() expects parameter 1 to be array, int given in %s on line %d
NULL
-- Iteration 4 --
Warning: usort() expects parameter 1 to be array, int given in %s on line %d
NULL
-- Iteration 5 --
Warning: usort() expects parameter 1 to be array, float given in %s on line %d
NULL
-- Iteration 6 --
Warning: usort() expects parameter 1 to be array, float given in %s on line %d
NULL
-- Iteration 7 --
Warning: usort() expects parameter 1 to be array, float given in %s on line %d
NULL
-- Iteration 8 --
Warning: usort() expects parameter 1 to be array, float given in %s on line %d
NULL
-- Iteration 9 --
Warning: usort() expects parameter 1 to be array, float given in %s on line %d
NULL
-- Iteration 10 --
Warning: usort() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 11 --
Warning: usort() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 12 --
Warning: usort() expects parameter 1 to be array, bool given in %s on line %d
NULL
-- Iteration 13 --
Warning: usort() expects parameter 1 to be array, bool given in %s on line %d
NULL
-- Iteration 14 --
Warning: usort() expects parameter 1 to be array, bool given in %s on line %d
NULL
-- Iteration 15 --
Warning: usort() expects parameter 1 to be array, bool given in %s on line %d
NULL
-- Iteration 16 --
Warning: usort() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 17 --
Warning: usort() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 18 --
bool(true)
-- Iteration 19 --
Warning: usort() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 20 --
Warning: usort() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 21 --
Warning: usort() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 22 --
Warning: usort() expects parameter 1 to be array, object given in %s on line %d
NULL
-- Iteration 23 --
Warning: usort() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 24 --
Warning: usort() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 25 --
Warning: usort() expects parameter 1 to be array, resource given in %s on line %d
NULL
===DONE===