Skip to content

Commit fe75c27

Browse files
committed
Add ReflectionProperty::isPromoted()
1 parent a4a52ed commit fe75c27

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5942,7 +5942,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
59425942
zend_string *doc_comment =
59435943
doc_comment_ast ? zend_string_copy(zend_ast_get_str(doc_comment_ast)) : NULL;
59445944
zend_property_info *prop = zend_declare_typed_property(
5945-
scope, name, &default_value, visibility, doc_comment, type);
5945+
scope, name, &default_value, visibility | ZEND_ACC_PROMOTED, doc_comment, type);
59465946
if (attributes_ast) {
59475947
zend_compile_attributes(
59485948
&prop->attributes, attributes_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY);

Zend/zend_compile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ typedef struct _zend_oparray_context {
209209
/* Static method or property | | | */
210210
#define ZEND_ACC_STATIC (1 << 4) /* | X | X | */
211211
/* | | | */
212+
/* Promoted property / parameter | | | */
213+
#define ZEND_ACC_PROMOTED (1 << 5) /* | | X | X */
214+
/* | | | */
212215
/* Final class or method | | | */
213216
#define ZEND_ACC_FINAL (1 << 5) /* X | X | | */
214217
/* | | | */

ext/reflection/php_reflection.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5461,6 +5461,14 @@ ZEND_METHOD(ReflectionProperty, isDefault)
54615461
}
54625462
/* }}} */
54635463

5464+
/* {{{ proto public bool ReflectionProperty::isPromoted()
5465+
Returns whether this property has been promoted from a constructor */
5466+
ZEND_METHOD(ReflectionProperty, isPromoted)
5467+
{
5468+
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PROMOTED);
5469+
}
5470+
/* }}} */
5471+
54645472
/* {{{ proto public int ReflectionProperty::getModifiers()
54655473
Returns a bitfield of the access modifiers for this property */
54665474
ZEND_METHOD(ReflectionProperty, getModifiers)

ext/reflection/php_reflection.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ public function isStatic() {}
413413
/** @return bool */
414414
public function isDefault() {}
415415

416+
public function isPromoted(): bool {}
417+
416418
/** @return int */
417419
public function getModifiers() {}
418420

ext/reflection/php_reflection_arginfo.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ ZEND_END_ARG_INFO()
312312

313313
#define arginfo_class_ReflectionProperty_isDefault arginfo_class_ReflectionFunctionAbstract___clone
314314

315+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionProperty_isPromoted, 0, 0, _IS_BOOL, 0)
316+
ZEND_END_ARG_INFO()
317+
315318
#define arginfo_class_ReflectionProperty_getModifiers arginfo_class_ReflectionFunctionAbstract___clone
316319

317320
#define arginfo_class_ReflectionProperty_getDeclaringClass arginfo_class_ReflectionFunctionAbstract___clone
@@ -324,8 +327,7 @@ ZEND_END_ARG_INFO()
324327

325328
#define arginfo_class_ReflectionProperty_hasType arginfo_class_ReflectionFunctionAbstract___clone
326329

327-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionProperty_hasDefaultValue, 0, 0, _IS_BOOL, 0)
328-
ZEND_END_ARG_INFO()
330+
#define arginfo_class_ReflectionProperty_hasDefaultValue arginfo_class_ReflectionProperty_isPromoted
329331

330332
#define arginfo_class_ReflectionProperty_getDefaultValue arginfo_class_ReflectionFunctionAbstract___clone
331333

@@ -604,6 +606,7 @@ ZEND_METHOD(ReflectionProperty, isPrivate);
604606
ZEND_METHOD(ReflectionProperty, isProtected);
605607
ZEND_METHOD(ReflectionProperty, isStatic);
606608
ZEND_METHOD(ReflectionProperty, isDefault);
609+
ZEND_METHOD(ReflectionProperty, isPromoted);
607610
ZEND_METHOD(ReflectionProperty, getModifiers);
608611
ZEND_METHOD(ReflectionProperty, getDeclaringClass);
609612
ZEND_METHOD(ReflectionProperty, getDocComment);
@@ -851,6 +854,7 @@ static const zend_function_entry class_ReflectionProperty_methods[] = {
851854
ZEND_ME(ReflectionProperty, isProtected, arginfo_class_ReflectionProperty_isProtected, ZEND_ACC_PUBLIC)
852855
ZEND_ME(ReflectionProperty, isStatic, arginfo_class_ReflectionProperty_isStatic, ZEND_ACC_PUBLIC)
853856
ZEND_ME(ReflectionProperty, isDefault, arginfo_class_ReflectionProperty_isDefault, ZEND_ACC_PUBLIC)
857+
ZEND_ME(ReflectionProperty, isPromoted, arginfo_class_ReflectionProperty_isPromoted, ZEND_ACC_PUBLIC)
854858
ZEND_ME(ReflectionProperty, getModifiers, arginfo_class_ReflectionProperty_getModifiers, ZEND_ACC_PUBLIC)
855859
ZEND_ME(ReflectionProperty, getDeclaringClass, arginfo_class_ReflectionProperty_getDeclaringClass, ZEND_ACC_PUBLIC)
856860
ZEND_ME(ReflectionProperty, getDocComment, arginfo_class_ReflectionProperty_getDocComment, ZEND_ACC_PUBLIC)

ext/reflection/tests/constructor_promotion.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $rc = new ReflectionClass(Test::class);
1515
echo $rc, "\n";
1616

1717
$y = $rc->getProperty('y');
18+
var_dump($y->isPromoted());
1819
var_dump($y->getDocComment());
1920

2021
?>
@@ -48,4 +49,5 @@ Class [ <user> class Test ] {
4849
}
4950
}
5051

52+
bool(true)
5153
string(24) "/** @SomeAnnotation() */"

0 commit comments

Comments
 (0)