Skip to content

Commit 049651d

Browse files
authored
Fix incorrect anonymous class type name assertion (#19316)
Since GH-17755 self and parent are compile-time resolved. We may now also encounter this type error at runtime outside of the class itself. Fixes GH-19304
1 parent bdffded commit 049651d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Zend/tests/gh19304.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-19304: Incorrect anonymous class type name assertion
3+
--FILE--
4+
<?php
5+
6+
$foo = new class {
7+
public self $v;
8+
};
9+
10+
try {
11+
$foo->v = 0;
12+
} catch (Error $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Cannot assign int to property class@anonymous::$v of type class@anonymous

Zend/zend_compile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,6 @@ static zend_string *resolve_class_name(zend_string *name, zend_class_entry *scop
13931393
* null byte here, to avoid larger parts of the type being omitted by printing code later. */
13941394
size_t len = strlen(ZSTR_VAL(name));
13951395
if (len != ZSTR_LEN(name)) {
1396-
ZEND_ASSERT(scope && "This should only happen with resolved types");
13971396
return zend_string_init(ZSTR_VAL(name), len, 0);
13981397
}
13991398
return zend_string_copy(name);

0 commit comments

Comments
 (0)