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
This commit is contained in:
Ilija Tovilo 2025-07-31 13:27:28 +02:00 committed by GitHub
parent bdffded054
commit 049651dccc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

18
Zend/tests/gh19304.phpt Normal file
View file

@ -0,0 +1,18 @@
--TEST--
GH-19304: Incorrect anonymous class type name assertion
--FILE--
<?php
$foo = new class {
public self $v;
};
try {
$foo->v = 0;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot assign int to property class@anonymous::$v of type class@anonymous

View file

@ -1393,7 +1393,6 @@ static zend_string *resolve_class_name(zend_string *name, zend_class_entry *scop
* null byte here, to avoid larger parts of the type being omitted by printing code later. */
size_t len = strlen(ZSTR_VAL(name));
if (len != ZSTR_LEN(name)) {
ZEND_ASSERT(scope && "This should only happen with resolved types");
return zend_string_init(ZSTR_VAL(name), len, 0);
}
return zend_string_copy(name);