summaryrefslogtreecommitdiff
path: root/Zend/tests/nullsafe_operator/013.phpt
blob: fd1fbc9006f6814d07809121f2e514434bd3d1f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--TEST--
Test nullsafe property in special functions
--FILE--
<?php

function dump_error(callable $callable) {
    try {
        var_dump($callable());
    } catch (Throwable $e) {
        var_dump($e->getMessage());
    }
}

function foo() {}

$foo = null;
dump_error(fn() => strlen($foo?->foo()));
dump_error(fn() => is_null($foo?->foo()));
dump_error(fn() => is_bool($foo?->foo()));
dump_error(fn() => is_int($foo?->foo()));
dump_error(fn() => is_scalar($foo?->foo()));
dump_error(fn() => boolval($foo?->foo()));
dump_error(fn() => defined($foo?->foo()));
dump_error(fn() => chr($foo?->foo()));
dump_error(fn() => ord($foo?->foo()));
dump_error(fn() => call_user_func_array($foo?->foo(), []));
dump_error(fn() => call_user_func_array('foo', $foo?->foo()));
dump_error(fn() => get_class($foo?->foo()));
dump_error(fn() => get_called_class($foo?->foo()));
dump_error(fn() => gettype($foo?->foo()));
dump_error(fn() => func_num_args($foo?->foo()));
dump_error(fn() => func_get_args($foo?->foo()));
dump_error(fn() => array_slice($foo?->foo(), 0));
dump_error(fn() => array_slice(['foo'], $foo?->foo()));
dump_error(fn() => array_slice(['foo'], 0, $foo?->foo()));
dump_error(fn() => array_key_exists($foo?->foo(), []));
dump_error(fn() => array_key_exists('foo', $foo?->foo()));

?>
--EXPECTF--
int(0)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
string(1) "%s"
int(0)
string(98) "call_user_func_array(): Argument #1 ($function) must be a valid callback, no array or string given"
string(77) "call_user_func_array(): Argument #2 ($args) must be of type array, null given"
string(69) "get_class(): Argument #1 ($object) must be of type object, null given"
string(55) "get_called_class() expects exactly 0 arguments, 1 given"
string(4) "NULL"
string(52) "func_num_args() expects exactly 0 arguments, 1 given"
string(52) "func_get_args() expects exactly 0 arguments, 1 given"
string(69) "array_slice(): Argument #1 ($array) must be of type array, null given"
array(1) {
  [0]=>
  string(3) "foo"
}
array(1) {
  [0]=>
  string(3) "foo"
}
bool(false)
string(74) "array_key_exists(): Argument #2 ($array) must be of type array, null given"