From 3dfbd229c9f3555793806521e2b55deae6140a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Mon, 28 Sep 2020 23:02:42 +0200 Subject: [PATCH 1/3] Reflection param renames amendment --- ext/reflection/php_reflection.stub.php | 14 +++++++------- ext/reflection/php_reflection_arginfo.h | 16 ++++++++-------- .../tests/ReflectionClass_toString_001.phpt | 6 +++--- ext/reflection/tests/parameters_001.phpt | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php index b150d1831ded..0e84d26c876e 100644 --- a/ext/reflection/php_reflection.stub.php +++ b/ext/reflection/php_reflection.stub.php @@ -194,7 +194,7 @@ public function getDeclaringClass() {} public function getPrototype() {} /** @return void */ - public function setAccessible(bool $isAccessible) {} + public function setAccessible(bool $accessible) {} } class ReflectionClass implements Reflector @@ -254,16 +254,16 @@ public function hasProperty(string $name) {} public function getProperty(string $name) {} /** @return ReflectionProperty[] */ - public function getProperties(?int $filter = null) {} + public function getProperties(?int $modifiers = null) {} /** @return bool */ public function hasConstant(string $name) {} /** @return array|null */ - public function getConstants(int $filter = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE) {} + public function getConstants(int $modifiers = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE) {} /** @return ReflectionClassConstant[] */ - public function getReflectionConstants(int $filter = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE) {} + public function getReflectionConstants(int $modifiers = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE) {} /** @return mixed */ public function getConstant(string $name) {} @@ -364,7 +364,7 @@ public function getAttributes(?string $name = null, int $flags = 0): array {} class ReflectionObject extends ReflectionClass { - public function __construct(object $argument) {} + public function __construct(object $object) {} } class ReflectionProperty implements Reflector @@ -415,7 +415,7 @@ public function getDeclaringClass() {} public function getDocComment() {} /** @return void */ - public function setAccessible(bool $isAccessible) {} + public function setAccessible(bool $accessible) {} /** @return ReflectionType|null */ public function getType() {} @@ -475,7 +475,7 @@ class ReflectionParameter implements Reflector final private function __clone() {} /** @param string|array|object $function */ - public function __construct($function, int|string $parameter) {} + public function __construct($function, int|string $param) {} public function __toString(): string {} diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h index 5457b14d4700..7cfb99779621 100644 --- a/ext/reflection/php_reflection_arginfo.h +++ b/ext/reflection/php_reflection_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 35e17de0cdf6c11a315f6d10fd711492d1da567c */ + * Stub hash: 7a05b86697bef8c44f537ff37f47764c0fa6be3f */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0) @@ -144,7 +144,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_ReflectionMethod_getPrototype arginfo_class_ReflectionFunctionAbstract___clone ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionMethod_setAccessible, 0, 0, 1) - ZEND_ARG_TYPE_INFO(0, isAccessible, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, accessible, _IS_BOOL, 0) ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass___clone arginfo_class_ReflectionFunctionAbstract___clone @@ -191,12 +191,14 @@ ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass_getProperty arginfo_class_ReflectionClass_hasMethod -#define arginfo_class_ReflectionClass_getProperties arginfo_class_ReflectionClass_getMethods +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_getProperties, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, modifiers, IS_LONG, 1, "null") +ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass_hasConstant arginfo_class_ReflectionClass_hasMethod ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_getConstants, 0, 0, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filter, IS_LONG, 0, "ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, modifiers, IS_LONG, 0, "ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE") ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass_getReflectionConstants arginfo_class_ReflectionClass_getConstants @@ -277,9 +279,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass_getAttributes arginfo_class_ReflectionFunctionAbstract_getAttributes -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionObject___construct, 0, 0, 1) - ZEND_ARG_TYPE_INFO(0, argument, IS_OBJECT, 0) -ZEND_END_ARG_INFO() +#define arginfo_class_ReflectionObject___construct arginfo_class_ReflectionClass_isInstance #define arginfo_class_ReflectionProperty___clone arginfo_class_ReflectionFunctionAbstract___clone @@ -363,7 +363,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionParameter___construct, 0, 0, 2) ZEND_ARG_INFO(0, function) - ZEND_ARG_TYPE_MASK(0, parameter, MAY_BE_LONG|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_MASK(0, param, MAY_BE_LONG|MAY_BE_STRING, NULL) ZEND_END_ARG_INFO() #define arginfo_class_ReflectionParameter___toString arginfo_class_ReflectionFunction___toString diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index 00e41bfcc9f6..12f92930e3d7 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -152,7 +152,7 @@ Class [ class ReflectionClass implements Reflector, String Method [ public method getProperties ] { - Parameters [1] { - Parameter #0 [ ?int $filter = null ] + Parameter #0 [ ?int $modifiers = null ] } } @@ -166,14 +166,14 @@ Class [ class ReflectionClass implements Reflector, String Method [ public method getConstants ] { - Parameters [1] { - Parameter #0 [ int $filter = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE ] + Parameter #0 [ int $modifiers = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE ] } } Method [ public method getReflectionConstants ] { - Parameters [1] { - Parameter #0 [ int $filter = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE ] + Parameter #0 [ int $modifiers = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE ] } } diff --git a/ext/reflection/tests/parameters_001.phpt b/ext/reflection/tests/parameters_001.phpt index 8299a63bf9d6..d50d1a1e720f 100644 --- a/ext/reflection/tests/parameters_001.phpt +++ b/ext/reflection/tests/parameters_001.phpt @@ -39,4 +39,4 @@ int(1) bool(false) bool(true) string(54) "The parameter specified by its name could not be found" -string(95) "ReflectionParameter::__construct(): Argument #2 ($parameter) must be greater than or equal to 0" +string(91) "ReflectionParameter::__construct(): Argument #2 ($param) must be greater than or equal to 0" From 5ed837cad60ff3734757a7234e1de82ac12a05ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 29 Sep 2020 09:19:45 +0200 Subject: [PATCH 2/3] Make the $modifiers parameter of ReflectionClass::get*Constants() nullable --- ext/reflection/php_reflection.c | 22 ++++++++++++++----- ext/reflection/php_reflection.stub.php | 4 ++-- ext/reflection/php_reflection_arginfo.h | 8 +++---- .../tests/ReflectionClass_toString_001.phpt | 4 ++-- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d4f89be69f52..7b9c37d1eb51 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4190,7 +4190,7 @@ ZEND_METHOD(ReflectionClass, getMethods) reflection_object *intern; zend_class_entry *ce; zend_function *mptr; - zend_long filter = 0; + zend_long filter; zend_bool filter_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) { @@ -4366,7 +4366,7 @@ ZEND_METHOD(ReflectionClass, getProperties) zend_class_entry *ce; zend_string *key; zend_property_info *prop_info; - zend_long filter = 0; + zend_long filter; zend_bool filter_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) { @@ -4422,12 +4422,17 @@ ZEND_METHOD(ReflectionClass, getConstants) zend_string *key; zend_class_constant *constant; zval val; - zend_long filter = ZEND_ACC_PPP_MASK; + zend_long filter; + zend_bool filter_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &filter) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) { RETURN_THROWS(); } + if (filter_is_null) { + filter = ZEND_ACC_PPP_MASK; + } + GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); @@ -4452,12 +4457,17 @@ ZEND_METHOD(ReflectionClass, getReflectionConstants) zend_class_entry *ce; zend_string *name; zend_class_constant *constant; - zend_long filter = ZEND_ACC_PPP_MASK; + zend_long filter; + zend_bool filter_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &filter) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) { RETURN_THROWS(); } + if (filter_is_null) { + filter = ZEND_ACC_PPP_MASK; + } + GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php index 0e84d26c876e..17def2a53afe 100644 --- a/ext/reflection/php_reflection.stub.php +++ b/ext/reflection/php_reflection.stub.php @@ -260,10 +260,10 @@ public function getProperties(?int $modifiers = null) {} public function hasConstant(string $name) {} /** @return array|null */ - public function getConstants(int $modifiers = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE) {} + public function getConstants(?int $modifiers = null) {} /** @return ReflectionClassConstant[] */ - public function getReflectionConstants(int $modifiers = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE) {} + public function getReflectionConstants(?int $modifiers = null) {} /** @return mixed */ public function getConstant(string $name) {} diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h index 7cfb99779621..9d69c2f908fc 100644 --- a/ext/reflection/php_reflection_arginfo.h +++ b/ext/reflection/php_reflection_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7a05b86697bef8c44f537ff37f47764c0fa6be3f */ + * Stub hash: 68c31a330622d4ea865e4e78dce04a8a27242ade */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0) @@ -197,11 +197,9 @@ ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass_hasConstant arginfo_class_ReflectionClass_hasMethod -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_getConstants, 0, 0, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, modifiers, IS_LONG, 0, "ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE") -ZEND_END_ARG_INFO() +#define arginfo_class_ReflectionClass_getConstants arginfo_class_ReflectionClass_getProperties -#define arginfo_class_ReflectionClass_getReflectionConstants arginfo_class_ReflectionClass_getConstants +#define arginfo_class_ReflectionClass_getReflectionConstants arginfo_class_ReflectionClass_getProperties #define arginfo_class_ReflectionClass_getConstant arginfo_class_ReflectionClass_hasMethod diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index 12f92930e3d7..f49507b74c0d 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -166,14 +166,14 @@ Class [ class ReflectionClass implements Reflector, String Method [ public method getConstants ] { - Parameters [1] { - Parameter #0 [ int $modifiers = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE ] + Parameter #0 [ ?int $modifiers = null ] } } Method [ public method getReflectionConstants ] { - Parameters [1] { - Parameter #0 [ int $modifiers = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE ] + Parameter #0 [ ?int $modifiers = null ] } } From 3913b34ffee79770c7c7978cb28524bce3771b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 29 Sep 2020 10:19:07 +0200 Subject: [PATCH 3/3] Address review --- ext/reflection/php_reflection.stub.php | 6 +++--- ext/reflection/php_reflection_arginfo.h | 10 ++++------ ext/reflection/tests/ReflectionClass_toString_001.phpt | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php index 17def2a53afe..cf6613c3a32e 100644 --- a/ext/reflection/php_reflection.stub.php +++ b/ext/reflection/php_reflection.stub.php @@ -254,16 +254,16 @@ public function hasProperty(string $name) {} public function getProperty(string $name) {} /** @return ReflectionProperty[] */ - public function getProperties(?int $modifiers = null) {} + public function getProperties(?int $filter = null) {} /** @return bool */ public function hasConstant(string $name) {} /** @return array|null */ - public function getConstants(?int $modifiers = null) {} + public function getConstants(?int $filter = null) {} /** @return ReflectionClassConstant[] */ - public function getReflectionConstants(?int $modifiers = null) {} + public function getReflectionConstants(?int $filter = null) {} /** @return mixed */ public function getConstant(string $name) {} diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h index 9d69c2f908fc..6044f7f2434c 100644 --- a/ext/reflection/php_reflection_arginfo.h +++ b/ext/reflection/php_reflection_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 68c31a330622d4ea865e4e78dce04a8a27242ade */ + * Stub hash: 4429ea0f96f81c3dbfb2a7e6e00ce49aea4bfeb1 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0) @@ -191,15 +191,13 @@ ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass_getProperty arginfo_class_ReflectionClass_hasMethod -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_getProperties, 0, 0, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, modifiers, IS_LONG, 1, "null") -ZEND_END_ARG_INFO() +#define arginfo_class_ReflectionClass_getProperties arginfo_class_ReflectionClass_getMethods #define arginfo_class_ReflectionClass_hasConstant arginfo_class_ReflectionClass_hasMethod -#define arginfo_class_ReflectionClass_getConstants arginfo_class_ReflectionClass_getProperties +#define arginfo_class_ReflectionClass_getConstants arginfo_class_ReflectionClass_getMethods -#define arginfo_class_ReflectionClass_getReflectionConstants arginfo_class_ReflectionClass_getProperties +#define arginfo_class_ReflectionClass_getReflectionConstants arginfo_class_ReflectionClass_getMethods #define arginfo_class_ReflectionClass_getConstant arginfo_class_ReflectionClass_hasMethod diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index f49507b74c0d..13b6130a407e 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -152,7 +152,7 @@ Class [ class ReflectionClass implements Reflector, String Method [ public method getProperties ] { - Parameters [1] { - Parameter #0 [ ?int $modifiers = null ] + Parameter #0 [ ?int $filter = null ] } } @@ -166,14 +166,14 @@ Class [ class ReflectionClass implements Reflector, String Method [ public method getConstants ] { - Parameters [1] { - Parameter #0 [ ?int $modifiers = null ] + Parameter #0 [ ?int $filter = null ] } } Method [ public method getReflectionConstants ] { - Parameters [1] { - Parameter #0 [ ?int $modifiers = null ] + Parameter #0 [ ?int $filter = null ] } }