methods-on-non-objects-usort.phpt 826 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. usort() in combination with "Call to a member function method() on null"
  3. --FILE--
  4. <?php
  5. set_error_handler(function($code, $message) {
  6. var_dump($code, $message);
  7. });
  8. $comparator= null;
  9. $list= [1, 4, 2, 3, -1];
  10. usort($list, function($a, $b) use ($comparator) {
  11. try {
  12. return $comparator->compare($a, $b);
  13. } catch (Error $e) {
  14. var_dump($e->getCode(), $e->getMessage());
  15. return 0;
  16. }
  17. });
  18. var_dump($list);
  19. echo "Alive\n";
  20. ?>
  21. --EXPECT--
  22. int(0)
  23. string(43) "Call to a member function compare() on null"
  24. int(0)
  25. string(43) "Call to a member function compare() on null"
  26. int(0)
  27. string(43) "Call to a member function compare() on null"
  28. int(0)
  29. string(43) "Call to a member function compare() on null"
  30. array(5) {
  31. [0]=>
  32. int(1)
  33. [1]=>
  34. int(4)
  35. [2]=>
  36. int(2)
  37. [3]=>
  38. int(3)
  39. [4]=>
  40. int(-1)
  41. }
  42. Alive