Skip to content

Commit f3415be

Browse files
committed
Add test for isset/empty behaviour with all container types
This is a seperate part of the RFC, but to already have a test
1 parent 0dcaab4 commit f3415be

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
--TEST--
2+
Behaviour of isset()/empty() with various container types
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';
7+
8+
foreach ($allContainers as $container) {
9+
echo zend_test_var_export($container), '[0]', "\n";
10+
11+
try {
12+
var_dump(isset($container[0]));
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
15+
}
16+
try {
17+
var_dump(empty($container[0]));
18+
} catch (Throwable $e) {
19+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
20+
}
21+
}
22+
23+
?>
24+
--EXPECT--
25+
NULL[0]
26+
bool(false)
27+
bool(true)
28+
false[0]
29+
bool(false)
30+
bool(true)
31+
true[0]
32+
bool(false)
33+
bool(true)
34+
4[0]
35+
bool(false)
36+
bool(true)
37+
5.5[0]
38+
bool(false)
39+
bool(true)
40+
'10'[0]
41+
bool(true)
42+
bool(false)
43+
'25.5'[0]
44+
bool(true)
45+
bool(false)
46+
'string'[0]
47+
bool(true)
48+
bool(false)
49+
[][0]
50+
bool(false)
51+
bool(true)
52+
STDERR[0]
53+
bool(false)
54+
bool(true)
55+
new stdClass()[0]
56+
Error: Cannot use object of type stdClass as array
57+
Error: Cannot use object of type stdClass as array
58+
new ArrayObject()[0]
59+
bool(false)
60+
bool(true)
61+
new A()[0]
62+
string(15) "A::offsetExists"
63+
int(0)
64+
string(12) "A::offsetGet"
65+
int(0)
66+
bool(true)
67+
string(15) "A::offsetExists"
68+
int(0)
69+
string(12) "A::offsetGet"
70+
int(0)
71+
bool(false)
72+
new B()[0]
73+
string(15) "B::offsetExists"
74+
int(0)
75+
string(12) "B::offsetGet"
76+
int(0)
77+
bool(true)
78+
string(15) "B::offsetExists"
79+
int(0)
80+
string(12) "B::offsetGet"
81+
int(0)
82+
bool(false)
83+
new DimensionRead()[0]
84+
string(27) "DimensionRead::offsetExists"
85+
int(0)
86+
string(24) "DimensionRead::offsetGet"
87+
int(0)
88+
bool(true)
89+
string(27) "DimensionRead::offsetExists"
90+
int(0)
91+
string(24) "DimensionRead::offsetGet"
92+
int(0)
93+
bool(false)
94+
new DimensionFetch()[0]
95+
string(27) "DimensionRead::offsetExists"
96+
int(0)
97+
string(24) "DimensionRead::offsetGet"
98+
int(0)
99+
bool(true)
100+
string(27) "DimensionRead::offsetExists"
101+
int(0)
102+
string(24) "DimensionRead::offsetGet"
103+
int(0)
104+
bool(false)
105+
new DimensionWrite()[0]
106+
Error: Cannot read offset of object of type DimensionWrite
107+
Error: Cannot read offset of object of type DimensionWrite
108+
new DimensionReadWrite()[0]
109+
string(32) "DimensionReadWrite::offsetExists"
110+
int(0)
111+
string(29) "DimensionReadWrite::offsetGet"
112+
int(0)
113+
bool(true)
114+
string(32) "DimensionReadWrite::offsetExists"
115+
int(0)
116+
string(29) "DimensionReadWrite::offsetGet"
117+
int(0)
118+
bool(false)
119+
new DimensionAppend()[0]
120+
Error: Cannot read offset of object of type DimensionAppend
121+
Error: Cannot read offset of object of type DimensionAppend
122+
new DimensionFetchAppend()[0]
123+
Error: Cannot read offset of object of type DimensionFetchAppend
124+
Error: Cannot read offset of object of type DimensionFetchAppend
125+
new DimensionUnset()[0]
126+
Error: Cannot read offset of object of type DimensionUnset
127+
Error: Cannot read offset of object of type DimensionUnset

0 commit comments

Comments
 (0)