Skip to content

Commit 6827e8d

Browse files
committed
Fix AST export of by-reference property hooks
ZEND_ACC_RETURN_REFERENCE shares a bit with ZEND_ACC_PRIVATE_SET, so &get was exported as private(set) get.
1 parent d7311be commit 6827e8d

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ PHP NEWS
144144
. Fixed bug GH-24480 (Finally block running a second time when a VM interrupt
145145
throws as the finally block returns to a "return" in its try block).
146146
(C. Scott Ananian)
147+
. Fixed AST export of by-reference property hooks. (Jorg Sowa)
147148

148149
- CLI:
149150
. Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work).
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
By-reference hook AST printing
3+
--FILE--
4+
<?php
5+
6+
try {
7+
assert(false && new class {
8+
public $prop1 { &get => $this->prop1; }
9+
public $prop2 {
10+
final &get {
11+
return $this->prop2;
12+
}
13+
}
14+
public private(set) int $prop3 { &get => $this->prop3; }
15+
});
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
?>
21+
--EXPECT--
22+
assert(false && new class {
23+
public $prop1 {
24+
&get => $this->prop1;
25+
}
26+
public $prop2 {
27+
final &get {
28+
return $this->prop2;
29+
}
30+
}
31+
public private(set) int $prop3 {
32+
&get => $this->prop3;
33+
}
34+
})

‎Zend/zend_ast.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,10 +1788,12 @@ static ZEND_COLD void zend_ast_export_hook_list(smart_str *str, zend_ast_list *h
17881788

17891789
for (uint32_t i = 0; i < hook_list->children; i++) {
17901790
zend_ast_decl *hook = (zend_ast_decl *)hook_list->child[i];
1791-
zend_ast_export_visibility(str, hook->flags, ZEND_MODIFIER_TARGET_PROPERTY);
17921791
if (hook->flags & ZEND_ACC_FINAL) {
17931792
smart_str_appends(str, "final ");
17941793
}
1794+
if (hook->flags & ZEND_ACC_RETURN_REFERENCE) {
1795+
smart_str_appendc(str, '&');
1796+
}
17951797
smart_str_append(str, hook->name);
17961798
zend_ast *body = hook->child[2];
17971799
if (body == NULL) {

0 commit comments

Comments
 (0)