1
0
mirror of https://github.com/php/php-src.git synced 2026-04-27 01:48:26 +02:00
Files
archived-php-src/ext/standard/tests/array/usort_variation7.phpt
T
Tim Düsterhus 08b2ab22f4 Include the source location in Closure names (#13550)
* Include the source location in Closure names

This change makes stack traces involving Closures, especially multiple
different Closures, much more useful, because it's more easily visible *which*
closure was called for a given stack frame.

The implementation is similar to that of anonymous classes which already
include the file name and line number within their generated classname.

* Update scripts/dev/bless_tests.php for closure naming

* Adjust existing tests for closure naming

* Adjust tests for closure naming that were not caught locally

* Drop the namespace from closure names

This is redundant with the included filename.

* Include filename and line number as separate keys in Closure debug info

* Fix test

* Fix test

* Include the surrounding class and function name in closure names

* Fix test

* Relax test expecations

* Fix tests after merge

* NEWS / UPGRADING
2024-04-12 18:21:13 +02:00

81 lines
2.3 KiB
PHP

--TEST--
Test usort() function : usage variations - Anonymous comparison function
--FILE--
<?php
/*
* Pass an anonymous comparison function as $cmp_function argument to test behaviour()
*/
echo "*** Testing usort() : usage variation ***\n";
$cmp_function = function($value1, $value2) {
if ($value1 == $value2) { return 0; }
else if ($value1 > $value2) { return 1; }
else { return -1; }
};
$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90);
echo "\n-- Anonymous 'cmp_function' with parameters passed by value --\n";
var_dump( usort($array_arg, $cmp_function) );
var_dump($array_arg);
$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple");
$cmp_function = function(&$value1, &$value2) {
if ($value1 == $value2) { return 0; }
else if ($value1 > $value2) { return 1; }
else { return -1; }
};
echo "\n-- Anonymous 'cmp_function' with parameters passed by reference --\n";
var_dump( usort($array_arg, $cmp_function) );
var_dump($array_arg);
?>
--EXPECTF--
*** Testing usort() : usage variation ***
-- Anonymous 'cmp_function' with parameters passed by value --
bool(true)
array(5) {
[0]=>
int(-70)
[1]=>
int(3)
[2]=>
int(24)
[3]=>
int(90)
[4]=>
int(100)
}
-- Anonymous 'cmp_function' with parameters passed by reference --
Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d
Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d
Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d
Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d
Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d
Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d
Warning: {closure:%s:%d}(): Argument #1 ($value1) must be passed by reference, value given in %s on line %d
Warning: {closure:%s:%d}(): Argument #2 ($value2) must be passed by reference, value given in %s on line %d
bool(true)
array(4) {
[0]=>
string(5) "Apple"
[1]=>
string(6) "Banana"
[2]=>
string(5) "Mango"
[3]=>
string(9) "Pineapple"
}