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