diff --git a/NEWS b/NEWS index 798f849854c1..85458d81dd94 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 export of readonly anonymous classes dropping the readonly + modifier. (Jorg Sowa) - CLI: . Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work). diff --git a/Zend/tests/assert/expect_readonly_anon_class.phpt b/Zend/tests/assert/expect_readonly_anon_class.phpt new file mode 100644 index 000000000000..5944475ffc4e --- /dev/null +++ b/Zend/tests/assert/expect_readonly_anon_class.phpt @@ -0,0 +1,22 @@ +--TEST-- +AST export of readonly anonymous class +--INI-- +zend.assertions=1 +--FILE-- +getMessage(), "\n"; +} +try { + assert(false && new #[A] readonly class(1) {}); +} catch (AssertionError $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +?> +--EXPECT-- +AssertionError: assert(false && new readonly class { +}) +AssertionError: assert(false && new #[A] readonly class(1) { +}) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 4e640a321d1f..f3031bbc930d 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -2311,6 +2311,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio if (decl->child[3]) { zend_ast_export_attributes(str, decl->child[3], indent, 0); } + if (decl->flags & ZEND_ACC_READONLY_CLASS) { + smart_str_appends(str, "readonly "); + } smart_str_appends(str, "class"); if (!zend_ast_is_list(ast->child[1]) || zend_ast_get_list(ast->child[1])->children) {