2014-04-29 03:44:24 +08:00
|
|
|
--TEST--
|
2014-07-06 23:07:41 +08:00
|
|
|
usort() in combination with "Call to a member function method() on null"
|
2014-04-29 03:44:24 +08:00
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
set_error_handler(function($code, $message) {
|
|
|
|
var_dump($code, $message);
|
|
|
|
});
|
|
|
|
|
|
|
|
$comparator= null;
|
|
|
|
$list= [1, 4, 2, 3, -1];
|
|
|
|
usort($list, function($a, $b) use ($comparator) {
|
2015-03-09 20:57:15 +08:00
|
|
|
try {
|
|
|
|
return $comparator->compare($a, $b);
|
2015-05-17 05:49:14 +08:00
|
|
|
} catch (Error $e) {
|
2015-03-09 20:57:15 +08:00
|
|
|
var_dump($e->getCode(), $e->getMessage());
|
|
|
|
return 0;
|
|
|
|
}
|
2014-04-29 03:44:24 +08:00
|
|
|
});
|
|
|
|
var_dump($list);
|
|
|
|
echo "Alive\n";
|
|
|
|
?>
|
2018-02-19 16:59:41 +08:00
|
|
|
--EXPECT--
|
2015-07-04 06:28:11 +08:00
|
|
|
int(0)
|
2014-07-06 23:07:41 +08:00
|
|
|
string(43) "Call to a member function compare() on null"
|
2015-07-04 06:28:11 +08:00
|
|
|
int(0)
|
2014-07-06 23:07:41 +08:00
|
|
|
string(43) "Call to a member function compare() on null"
|
2015-07-04 06:28:11 +08:00
|
|
|
int(0)
|
2014-07-06 23:07:41 +08:00
|
|
|
string(43) "Call to a member function compare() on null"
|
2015-07-04 06:28:11 +08:00
|
|
|
int(0)
|
2014-07-06 23:07:41 +08:00
|
|
|
string(43) "Call to a member function compare() on null"
|
2014-04-29 03:44:24 +08:00
|
|
|
array(5) {
|
|
|
|
[0]=>
|
2015-01-14 17:22:58 +08:00
|
|
|
int(1)
|
2014-04-29 03:44:24 +08:00
|
|
|
[1]=>
|
2015-01-14 17:22:58 +08:00
|
|
|
int(4)
|
2014-04-29 03:44:24 +08:00
|
|
|
[2]=>
|
|
|
|
int(2)
|
|
|
|
[3]=>
|
2015-01-14 17:22:58 +08:00
|
|
|
int(3)
|
2014-04-29 03:44:24 +08:00
|
|
|
[4]=>
|
2015-01-14 17:22:58 +08:00
|
|
|
int(-1)
|
2014-04-29 03:44:24 +08:00
|
|
|
}
|
|
|
|
Alive
|