forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SplObjectStorage_coalesce.phpt
91 lines (88 loc) · 2.04 KB
/
SplObjectStorage_coalesce.phpt
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
--TEST--
SplObjectStorage magic operators
--FILE--
<?php
$i = 'dynamic';
$v = $i . '_';
$s = new SplObjectStorage();
$o1 = new Stdclass;
$o2 = new Stdclass;
var_dump($s[$o1] ?? 'default');
var_dump($s[$o1] ??= $i);
var_dump($s[$o1] ??= null);
var_dump($s[$o1] ??= false);
var_dump($s[$o1] ?? $i);
var_dump(isset($s[$o1]));
var_dump(empty($s[$o1]));
echo "o2\n";
var_dump(isset($s[$o2]));
var_dump(empty($s[$o2]));
$s[$o2] = null;
var_dump($s[$o2] ?? new stdClass());
echo "check isset/empty/contains for null. offsetExists returns true as long as the entry is there.\n";
var_dump(isset($s[$o2]));
var_dump(empty($s[$o2]));
var_dump($s->contains($o2));
echo "check isset/empty/contains for false.\n";
$s[$o2] = false;
var_dump(isset($s[$o2]));
var_dump(empty($s[$o2]));
var_dump($s->contains($o2));
try {
$s['invalid'] = 123;
} catch (Error $e) {
printf("%s: %s\n", $e::class, $e->getMessage());
}
try {
var_dump(isset($s['invalid']));
} catch (Error $e) {
printf("%s: %s\n", $e::class, $e->getMessage());
}
$a = &$s[$o1];
var_dump($s);
?>
--EXPECTF--
string(7) "default"
string(7) "dynamic"
string(7) "dynamic"
string(7) "dynamic"
string(7) "dynamic"
bool(true)
bool(false)
o2
bool(false)
bool(true)
object(stdClass)#4 (0) {
}
check isset/empty/contains for null. offsetExists returns true as long as the entry is there.
bool(true)
bool(true)
bool(true)
check isset/empty/contains for false.
bool(true)
bool(true)
bool(true)
TypeError: SplObjectStorage::offsetSet(): Argument #1 ($object) must be of type object, string given
TypeError: SplObjectStorage::offsetExists(): Argument #1 ($object) must be of type object, string given
Notice: Indirect modification of overloaded element of SplObjectStorage has no effect in %s on line 38
object(SplObjectStorage)#1 (1) {
["storage":"SplObjectStorage":private]=>
array(2) {
[0]=>
array(2) {
["obj"]=>
object(stdClass)#2 (0) {
}
["inf"]=>
string(7) "dynamic"
}
[1]=>
array(2) {
["obj"]=>
object(stdClass)#3 (0) {
}
["inf"]=>
bool(false)
}
}
}