013.phpt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --TEST--
  2. Test nullsafe property in special functions
  3. --FILE--
  4. <?php
  5. function dump_error(callable $callable) {
  6. try {
  7. var_dump($callable());
  8. } catch (Throwable $e) {
  9. var_dump($e->getMessage());
  10. }
  11. }
  12. function foo() {}
  13. $foo = null;
  14. dump_error(fn() => strlen($foo?->foo()));
  15. dump_error(fn() => is_null($foo?->foo()));
  16. dump_error(fn() => is_bool($foo?->foo()));
  17. dump_error(fn() => is_int($foo?->foo()));
  18. dump_error(fn() => is_scalar($foo?->foo()));
  19. dump_error(fn() => boolval($foo?->foo()));
  20. dump_error(fn() => defined($foo?->foo()));
  21. dump_error(fn() => chr($foo?->foo()));
  22. dump_error(fn() => ord($foo?->foo()));
  23. dump_error(fn() => call_user_func_array($foo?->foo(), []));
  24. dump_error(fn() => call_user_func_array('foo', $foo?->foo()));
  25. dump_error(fn() => get_class($foo?->foo()));
  26. dump_error(fn() => get_called_class($foo?->foo()));
  27. dump_error(fn() => gettype($foo?->foo()));
  28. dump_error(fn() => func_num_args($foo?->foo()));
  29. dump_error(fn() => func_get_args($foo?->foo()));
  30. dump_error(fn() => array_slice($foo?->foo(), 0));
  31. dump_error(fn() => array_slice(['foo'], $foo?->foo()));
  32. dump_error(fn() => array_slice(['foo'], 0, $foo?->foo()));
  33. dump_error(fn() => array_key_exists($foo?->foo(), []));
  34. dump_error(fn() => array_key_exists('foo', $foo?->foo()));
  35. ?>
  36. --EXPECTF--
  37. Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in %s on line %d
  38. int(0)
  39. bool(true)
  40. bool(false)
  41. bool(false)
  42. bool(false)
  43. bool(false)
  44. Deprecated: defined(): Passing null to parameter #1 ($constant_name) of type string is deprecated in %s on line %d
  45. bool(false)
  46. Deprecated: chr(): Passing null to parameter #1 ($codepoint) of type int is deprecated in %s on line %d
  47. string(1) "%s"
  48. Deprecated: ord(): Passing null to parameter #1 ($character) of type string is deprecated in %s on line %d
  49. int(0)
  50. string(98) "call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given"
  51. string(77) "call_user_func_array(): Argument #2 ($args) must be of type array, null given"
  52. string(69) "get_class(): Argument #1 ($object) must be of type object, null given"
  53. string(55) "get_called_class() expects exactly 0 arguments, 1 given"
  54. string(4) "NULL"
  55. string(52) "func_num_args() expects exactly 0 arguments, 1 given"
  56. string(52) "func_get_args() expects exactly 0 arguments, 1 given"
  57. string(69) "array_slice(): Argument #1 ($array) must be of type array, null given"
  58. Deprecated: array_slice(): Passing null to parameter #2 ($offset) of type int is deprecated in %s on line %d
  59. array(1) {
  60. [0]=>
  61. string(3) "foo"
  62. }
  63. array(1) {
  64. [0]=>
  65. string(3) "foo"
  66. }
  67. bool(false)
  68. string(74) "array_key_exists(): Argument #2 ($array) must be of type array, null given"