From 049651dccc501f323b4589aa6d42b20c3e9f33ab Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 31 Jul 2025 13:27:28 +0200 Subject: [PATCH] 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 --- 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 00000000000..c77fc2d6fac --- /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 19252c26f86..e66389bc7ee 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);