Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle attributes for promoted properties
  • Loading branch information
nikic committed Jun 5, 2020
commit a4a52edaad84ae4d978e2d38ff117800230c4781
22 changes: 22 additions & 0 deletions Zend/tests/ctor_promotion_attributes.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Attributes on promoted properties are assigned to both the property and parameter
--FILE--
<?php

class Test {
public function __construct(
<<NonNegative>>
public int $num,
) {}
}

$prop = new ReflectionProperty(Test::class, 'num');
var_dump($prop->getAttributes()[0]->getName());

$param = new ReflectionParameter([Test::class, '__construct'], 'num');
var_dump($param->getAttributes()[0]->getName());

?>
--EXPECT--
string(11) "NonNegative"
string(11) "NonNegative"
6 changes: 5 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5941,8 +5941,12 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall

zend_string *doc_comment =
doc_comment_ast ? zend_string_copy(zend_ast_get_str(doc_comment_ast)) : NULL;
zend_declare_typed_property(
zend_property_info *prop = zend_declare_typed_property(
scope, name, &default_value, visibility, doc_comment, type);
if (attributes_ast) {
zend_compile_attributes(
&prop->attributes, attributes_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY);
}
}
}

Expand Down