diff --git a/NEWS b/NEWS index 798f849854c1..2cdab395a658 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,7 @@ PHP NEWS (Marti2203). . Fixed bug GH-24989 (Use-after-free in GC when an exception is thrown). (David Carlier) + . Fixed AST export of by-reference property hooks. (Jorg Sowa) - CLI: . Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work). diff --git a/Zend/tests/property_hooks/ast_printing_by_ref.phpt b/Zend/tests/property_hooks/ast_printing_by_ref.phpt new file mode 100644 index 000000000000..f543c562d767 --- /dev/null +++ b/Zend/tests/property_hooks/ast_printing_by_ref.phpt @@ -0,0 +1,30 @@ +--TEST-- +By-reference hook AST printing +--FILE-- + $this->prop1; } + public $prop2 { + final &get { + return $this->prop2; + } + } + }); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +assert(false && new class { + public $prop1 { + &get => $this->prop1; + } + public $prop2 { + final &get { + return $this->prop2; + } + } +}) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 4e640a321d1f..c4c19257e98b 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1769,10 +1769,12 @@ static ZEND_COLD void zend_ast_export_hook_list(smart_str *str, zend_ast_list *h for (uint32_t i = 0; i < hook_list->children; i++) { zend_ast_decl *hook = (zend_ast_decl *)hook_list->child[i]; - zend_ast_export_visibility(str, hook->flags, ZEND_MODIFIER_TARGET_PROPERTY); if (hook->flags & ZEND_ACC_FINAL) { smart_str_appends(str, "final "); } + if (hook->flags & ZEND_ACC_RETURN_REFERENCE) { + smart_str_appendc(str, '&'); + } smart_str_append(str, hook->name); zend_ast *body = hook->child[2]; if (body == NULL) {