Skip to content

Commit a4a52ed

Browse files
committed
Handle attributes for promoted properties
1 parent 1a9dfaf commit a4a52ed

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Attributes on promoted properties are assigned to both the property and parameter
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public function __construct(
8+
<<NonNegative>>
9+
public int $num,
10+
) {}
11+
}
12+
13+
$prop = new ReflectionProperty(Test::class, 'num');
14+
var_dump($prop->getAttributes()[0]->getName());
15+
16+
$param = new ReflectionParameter([Test::class, '__construct'], 'num');
17+
var_dump($param->getAttributes()[0]->getName());
18+
19+
?>
20+
--EXPECT--
21+
string(11) "NonNegative"
22+
string(11) "NonNegative"

Zend/zend_compile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5941,8 +5941,12 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
59415941

59425942
zend_string *doc_comment =
59435943
doc_comment_ast ? zend_string_copy(zend_ast_get_str(doc_comment_ast)) : NULL;
5944-
zend_declare_typed_property(
5944+
zend_property_info *prop = zend_declare_typed_property(
59455945
scope, name, &default_value, visibility, doc_comment, type);
5946+
if (attributes_ast) {
5947+
zend_compile_attributes(
5948+
&prop->attributes, attributes_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY);
5949+
}
59465950
}
59475951
}
59485952

0 commit comments

Comments
 (0)