Skip to content

Commit abe53ed

Browse files
committed
Add a class loading test
1 parent 236a72f commit abe53ed

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
Class loading issues related to multiple class types in a union
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public X|Y|Z|int $prop;
8+
}
9+
10+
spl_autoload_register(function($class) {
11+
echo "Loading $class\n";
12+
});
13+
14+
$test = new Test;
15+
16+
// Should not cause class loading, as not an object
17+
$test->prop = 42;
18+
var_dump($test->prop);
19+
20+
// Should try to load both classes
21+
try {
22+
$test->prop = new stdClass;
23+
} catch (TypeError $e) {
24+
echo $e->getMessage(), "\n";
25+
}
26+
27+
if (true) {
28+
class X {}
29+
}
30+
31+
// Should not cause class loading, as X is already loaded
32+
try {
33+
$test->prop = new X;
34+
} catch (TypeError $e) {
35+
echo $e->getMessage(), "\n";
36+
}
37+
var_dump($test->prop);
38+
39+
if (true) {
40+
class Z {}
41+
}
42+
43+
// TODO: Should this load class Y or not?
44+
try {
45+
$test->prop = new Z;
46+
} catch (TypeError $e) {
47+
echo $e->getMessage(), "\n";
48+
}
49+
var_dump($test->prop);
50+
51+
?>
52+
--EXPECT--
53+
int(42)
54+
Loading X
55+
Loading Y
56+
Loading Z
57+
Cannot assign stdClass to property Test::$prop of type X|Y|Z|int
58+
object(X)#3 (0) {
59+
}
60+
Loading Y
61+
object(Z)#5 (0) {
62+
}

0 commit comments

Comments
 (0)