From ed82368caad95d765c557fdc80e24407bce20504 Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Fri, 30 Oct 2026 20:25:45 +0100 Subject: [PATCH] Fix AST printing of qualified names in name lists --- NEWS | 2 + .../assert/expect_qualified_name_lists.phpt | 37 +++++++++++++++++++ Zend/zend_ast.c | 4 +- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/assert/expect_qualified_name_lists.phpt diff --git a/NEWS b/NEWS index 798f849854c1..e7f31fa7e742 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,8 @@ PHP NEWS (Marti2203). . Fixed bug GH-24989 (Use-after-free in GC when an exception is thrown). (David Carlier) + . Fixed AST printing dropping fully qualified and namespace-relative prefixes + of class names in implements, catch, and trait use lists. (Jorg Sowa) - CLI: . Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work). diff --git a/Zend/tests/assert/expect_qualified_name_lists.phpt b/Zend/tests/assert/expect_qualified_name_lists.phpt new file mode 100644 index 000000000000..24c54b7bee08 --- /dev/null +++ b/Zend/tests/assert/expect_qualified_name_lists.phpt @@ -0,0 +1,37 @@ +--TEST-- +AST printing of fully qualified and namespace-relative names in name lists +--INI-- +zend.assertions=1 +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECT-- +assert(false && function () { + class C implements \A, namespace\B, C { + use \T1, namespace\T2, T3 { + \T1::foo insteadof namespace\T2, T3; + namespace\T2::foo as bar; + } + } + + try { + } catch (\E1|namespace\E2|E3 $e) { + } +}) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 4e640a321d1f..25612155aa74 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1496,7 +1496,7 @@ static ZEND_COLD void zend_ast_export_name_list_ex(smart_str *str, zend_ast_list if (i != 0) { smart_str_appends(str, separator); } - zend_ast_export_name(str, list->child[i], 0, indent); + zend_ast_export_ns_name(str, list->child[i], 0, indent); i++; } } @@ -2468,7 +2468,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio break; case ZEND_AST_METHOD_REFERENCE: if (ast->child[0]) { - zend_ast_export_name(str, ast->child[0], 0, indent); + zend_ast_export_ns_name(str, ast->child[0], 0, indent); smart_str_appends(str, "::"); } zend_ast_export_name(str, ast->child[1], 0, indent);