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
Add ReflectionProperty::isPromoted()
  • Loading branch information
nikic committed Jun 5, 2020
commit fe75c27d5aa0c931024d7da4a6259dc16be0c024
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5942,7 +5942,7 @@ 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_property_info *prop = zend_declare_typed_property(
scope, name, &default_value, visibility, doc_comment, type);
scope, name, &default_value, visibility | ZEND_ACC_PROMOTED, doc_comment, type);
if (attributes_ast) {
zend_compile_attributes(
&prop->attributes, attributes_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY);
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ typedef struct _zend_oparray_context {
/* Static method or property | | | */
#define ZEND_ACC_STATIC (1 << 4) /* | X | X | */
/* | | | */
/* Promoted property / parameter | | | */
#define ZEND_ACC_PROMOTED (1 << 5) /* | | X | X */
/* | | | */
/* Final class or method | | | */
#define ZEND_ACC_FINAL (1 << 5) /* X | X | | */
/* | | | */
Expand Down
8 changes: 8 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -5461,6 +5461,14 @@ ZEND_METHOD(ReflectionProperty, isDefault)
}
/* }}} */

/* {{{ proto public bool ReflectionProperty::isPromoted()
Returns whether this property has been promoted from a constructor */
ZEND_METHOD(ReflectionProperty, isPromoted)
{
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PROMOTED);
}
/* }}} */

/* {{{ proto public int ReflectionProperty::getModifiers()
Returns a bitfield of the access modifiers for this property */
ZEND_METHOD(ReflectionProperty, getModifiers)
Expand Down
2 changes: 2 additions & 0 deletions ext/reflection/php_reflection.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ public function isStatic() {}
/** @return bool */
public function isDefault() {}

public function isPromoted(): bool {}

/** @return int */
public function getModifiers() {}

Expand Down
8 changes: 6 additions & 2 deletions ext/reflection/php_reflection_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ ZEND_END_ARG_INFO()

#define arginfo_class_ReflectionProperty_isDefault arginfo_class_ReflectionFunctionAbstract___clone

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionProperty_isPromoted, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_ReflectionProperty_getModifiers arginfo_class_ReflectionFunctionAbstract___clone

#define arginfo_class_ReflectionProperty_getDeclaringClass arginfo_class_ReflectionFunctionAbstract___clone
Expand All @@ -324,8 +327,7 @@ ZEND_END_ARG_INFO()

#define arginfo_class_ReflectionProperty_hasType arginfo_class_ReflectionFunctionAbstract___clone

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionProperty_hasDefaultValue, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionProperty_hasDefaultValue arginfo_class_ReflectionProperty_isPromoted

#define arginfo_class_ReflectionProperty_getDefaultValue arginfo_class_ReflectionFunctionAbstract___clone

Expand Down Expand Up @@ -604,6 +606,7 @@ ZEND_METHOD(ReflectionProperty, isPrivate);
ZEND_METHOD(ReflectionProperty, isProtected);
ZEND_METHOD(ReflectionProperty, isStatic);
ZEND_METHOD(ReflectionProperty, isDefault);
ZEND_METHOD(ReflectionProperty, isPromoted);
ZEND_METHOD(ReflectionProperty, getModifiers);
ZEND_METHOD(ReflectionProperty, getDeclaringClass);
ZEND_METHOD(ReflectionProperty, getDocComment);
Expand Down Expand Up @@ -851,6 +854,7 @@ static const zend_function_entry class_ReflectionProperty_methods[] = {
ZEND_ME(ReflectionProperty, isProtected, arginfo_class_ReflectionProperty_isProtected, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionProperty, isStatic, arginfo_class_ReflectionProperty_isStatic, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionProperty, isDefault, arginfo_class_ReflectionProperty_isDefault, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionProperty, isPromoted, arginfo_class_ReflectionProperty_isPromoted, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionProperty, getModifiers, arginfo_class_ReflectionProperty_getModifiers, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionProperty, getDeclaringClass, arginfo_class_ReflectionProperty_getDeclaringClass, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionProperty, getDocComment, arginfo_class_ReflectionProperty_getDocComment, ZEND_ACC_PUBLIC)
Expand Down
2 changes: 2 additions & 0 deletions ext/reflection/tests/constructor_promotion.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $rc = new ReflectionClass(Test::class);
echo $rc, "\n";

$y = $rc->getProperty('y');
var_dump($y->isPromoted());
var_dump($y->getDocComment());

?>
Expand Down Expand Up @@ -48,4 +49,5 @@ Class [ <user> class Test ] {
}
}

bool(true)
string(24) "/** @SomeAnnotation() */"