Skip to content

Commit a5d34b4

Browse files
committed
Fix AST export of property hook parameters and attributes (GH-25421)
set(int $v) => $v was exported as set => $v, and hook attributes were dropped. Closes GH-25421
1 parent 4452ae4 commit a5d34b4

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ PHP NEWS
3434
. Fixed bug GH-25311 (Assertion ret == SUCCESS in array_map()/array_filter()
3535
after delayed out-of-memory). (ndossche)
3636
. Fixed AST export of by-reference property hooks. (Jorg Sowa)
37+
. Fixed AST export of property hook parameter lists and attributes.
38+
(Jorg Sowa)
3739

3840
- Curl:
3941
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
Hook parameter list and attributes AST printing
3+
--FILE--
4+
<?php
5+
6+
try {
7+
assert(false && new class {
8+
public int $prop1 {
9+
set(int $value) => $value * 2;
10+
}
11+
public $prop2 {
12+
#[A]
13+
get => $this->prop2;
14+
#[A(1), B]
15+
#[C]
16+
final set($value) {
17+
$this->prop2 = $value;
18+
}
19+
}
20+
public string $prop3 {
21+
set(#[SensitiveParameter] string|int $value) => (string) $value;
22+
}
23+
public $prop4 {
24+
#[A] final &get => $this->prop4;
25+
}
26+
public function __construct(
27+
public int $prop5 {
28+
#[A]
29+
set(int $value) => $value + 1;
30+
},
31+
) {}
32+
});
33+
} catch (Error $e) {
34+
echo $e->getMessage(), "\n";
35+
}
36+
37+
?>
38+
--EXPECT--
39+
assert(false && new class {
40+
public int $prop1 {
41+
set(int $value) => $value * 2;
42+
}
43+
public $prop2 {
44+
#[A]
45+
get => $this->prop2;
46+
#[A(1), B]
47+
#[C]
48+
final set($value) {
49+
$this->prop2 = $value;
50+
}
51+
}
52+
public string $prop3 {
53+
set(#[SensitiveParameter] string|int $value) => (string)$value;
54+
}
55+
public $prop4 {
56+
#[A]
57+
final &get => $this->prop4;
58+
}
59+
public function __construct(public int $prop5 {
60+
#[A]
61+
set(int $value) => $value + 1;
62+
}) {
63+
}
64+
65+
})

‎Zend/zend_ast.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,13 +2255,21 @@ static ZEND_COLD void zend_ast_export_hook_list(smart_str *str, const zend_ast_l
22552255

22562256
for (uint32_t i = 0; i < hook_list->children; i++) {
22572257
const zend_ast_decl *hook = (const zend_ast_decl *)hook_list->child[i];
2258+
if (hook->child[4]) {
2259+
zend_ast_export_attributes(str, hook->child[4], indent, 1);
2260+
}
22582261
if (hook->flags & ZEND_ACC_FINAL) {
22592262
smart_str_appends(str, "final ");
22602263
}
22612264
if (hook->flags & ZEND_ACC_RETURN_REFERENCE) {
22622265
smart_str_appendc(str, '&');
22632266
}
22642267
smart_str_append(str, hook->name);
2268+
if (hook->child[0]) {
2269+
smart_str_appendc(str, '(');
2270+
zend_ast_export_ex(str, hook->child[0], 0, indent);
2271+
smart_str_appendc(str, ')');
2272+
}
22652273
zend_ast *body = hook->child[2];
22662274
if (body == NULL) {
22672275
smart_str_appendc(str, ';');

0 commit comments

Comments
 (0)