Skip to content

Commit f475edc

Browse files
qxzkjpnikic
authored andcommitted
Fixed bug #79897: Promoted constructor params with attribs cause crash
This was caused by the attribute AST being used twice, and was fixed by creating a temporary copy of it (and destroying said copy) when neccesary.
1 parent 3690a80 commit f475edc

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
(cmb)
88
. Fixed bug #79108 (Referencing argument in a function makes it a reference
99
in the stack trace). (Nikita)
10+
. Fixed bug #79897 (Promoted constructor params with attribs cause crash).
11+
(Deus Kane)
1012

1113
- JIT:
1214
. Fixed bug #79864 (JIT segfault in Symfony OptionsResolver). (Dmitry)

Zend/tests/bug79897.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
bug79897: Promoted constructor params with attribs cause crash
3+
--FILE--
4+
<?php
5+
6+
@@Attribute
7+
class B {
8+
public function __construct($value)
9+
{
10+
}
11+
}
12+
13+
class A {
14+
public function __construct(
15+
@@B(12) public $b
16+
)
17+
{
18+
}
19+
}
20+
21+
var_dump((new ReflectionParameter(['A', '__construct'], 'b'))->getAttributes()[0]->getArguments());
22+
var_dump((new ReflectionProperty('A', 'b'))->getAttributes()[0]->getArguments());
23+
?>
24+
--EXPECT--
25+
array(1) {
26+
[0]=>
27+
int(12)
28+
}
29+
array(1) {
30+
[0]=>
31+
int(12)
32+
}

Zend/zend_compile.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6197,6 +6197,12 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
61976197
zend_op *opline;
61986198
zend_arg_info *arg_info;
61996199

6200+
zend_ast_ref *attributes_copy = NULL;
6201+
6202+
if (visibility && attributes_ast) {
6203+
attributes_copy = zend_ast_copy(attributes_ast);
6204+
}
6205+
62006206
if (zend_is_auto_global(name)) {
62016207
zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign auto-global variable %s",
62026208
ZSTR_VAL(name));
@@ -6350,7 +6356,8 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
63506356
scope, name, &default_value, visibility | ZEND_ACC_PROMOTED, doc_comment, type);
63516357
if (attributes_ast) {
63526358
zend_compile_attributes(
6353-
&prop->attributes, attributes_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY);
6359+
&prop->attributes, GC_AST(attributes_copy), 0, ZEND_ATTRIBUTE_TARGET_PROPERTY);
6360+
zend_ast_ref_destroy(attributes_copy);
63546361
}
63556362
}
63566363
}

0 commit comments

Comments
 (0)