[php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Jorg Sowa | Date: | Sat, 31 Oct 2026 15:20:04 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143072@lists.php.net to get a copy of this message | ||
Author: Jorg Sowa (jorgsowa)
Date: 2026-10-31T16:17:26+01:00
Commit: https://github.com/php/php-src/commit/fc207d7be6f5144ac074127b543b91203007956a
Raw diff: https://github.com/php/php-src/commit/fc207d7be6f5144ac074127b543b91203007956a.diff
Merge branch 'PHP-8.4' into PHP-8.5
Changed paths:
A Zend/tests/assert/expect_readonly_anon_class.phpt
M NEWS
M Zend/zend_ast.c
Diff:
diff --git a/NEWS b/NEWS
index c91e327164a2..f4de4f4a97af 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,8 @@ PHP NEWS
(Marti2203).
. Fixed AST printing dropping final on class constants and properties, and
abstract on properties. (Jorg Sowa)
+ . 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--
+<?php
+try {
+ assert(false && new readonly class {});
+} catch (AssertionError $e) {
+ echo $e::class, ': ', $e->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 fb0aa22f3367..837257451047 100644
--- a/Zend/zend_ast.c
+++ b/Zend/zend_ast.c
@@ -2571,6 +2571,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) {