From 11f7790449e312c11494075e6b133f9e39816b8a Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 30 Jul 2025 17:31:54 +0200 Subject: [PATCH] Fix incorrect anonymous class type name assertion 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 --- Zend/tests/gh19304.phpt | 18 ++++++++++++++++++ Zend/zend_compile.c | 1 - 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/gh19304.phpt diff --git a/Zend/tests/gh19304.phpt b/Zend/tests/gh19304.phpt new file mode 100644 index 0000000000000..c77fc2d6facc2 --- /dev/null +++ b/Zend/tests/gh19304.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-19304: Incorrect anonymous class type name assertion +--FILE-- +v = 0; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Cannot assign int to property class@anonymous::$v of type class@anonymous diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 19252c26f862e..e66389bc7ee5b 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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);