Skip to content

Commit 351776e

Browse files
committed
Make the $filter parameter of ReflectionClass::get*Constants() nullable
1 parent e195992 commit 351776e

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

ext/reflection/php_reflection.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4190,7 +4190,7 @@ ZEND_METHOD(ReflectionClass, getMethods)
41904190
reflection_object *intern;
41914191
zend_class_entry *ce;
41924192
zend_function *mptr;
4193-
zend_long filter = 0;
4193+
zend_long filter;
41944194
zend_bool filter_is_null = 1;
41954195

41964196
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) {
@@ -4366,7 +4366,7 @@ ZEND_METHOD(ReflectionClass, getProperties)
43664366
zend_class_entry *ce;
43674367
zend_string *key;
43684368
zend_property_info *prop_info;
4369-
zend_long filter = 0;
4369+
zend_long filter;
43704370
zend_bool filter_is_null = 1;
43714371

43724372
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) {
@@ -4422,12 +4422,17 @@ ZEND_METHOD(ReflectionClass, getConstants)
44224422
zend_string *key;
44234423
zend_class_constant *constant;
44244424
zval val;
4425-
zend_long filter = ZEND_ACC_PPP_MASK;
4425+
zend_long filter;
4426+
zend_bool filter_is_null = 1;
44264427

4427-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &filter) == FAILURE) {
4428+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) {
44284429
RETURN_THROWS();
44294430
}
44304431

4432+
if (filter_is_null) {
4433+
filter = ZEND_ACC_PPP_MASK;
4434+
}
4435+
44314436
GET_REFLECTION_OBJECT_PTR(ce);
44324437

44334438
array_init(return_value);
@@ -4452,12 +4457,17 @@ ZEND_METHOD(ReflectionClass, getReflectionConstants)
44524457
zend_class_entry *ce;
44534458
zend_string *name;
44544459
zend_class_constant *constant;
4455-
zend_long filter = ZEND_ACC_PPP_MASK;
4460+
zend_long filter;
4461+
zend_bool filter_is_null = 1;
44564462

4457-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &filter) == FAILURE) {
4463+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) {
44584464
RETURN_THROWS();
44594465
}
44604466

4467+
if (filter_is_null) {
4468+
filter = ZEND_ACC_PPP_MASK;
4469+
}
4470+
44614471
GET_REFLECTION_OBJECT_PTR(ce);
44624472

44634473
array_init(return_value);

ext/reflection/php_reflection.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,10 @@ public function getProperties(?int $filter = null) {}
260260
public function hasConstant(string $name) {}
261261

262262
/** @return array|null */
263-
public function getConstants(int $filter = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE) {}
263+
public function getConstants(?int $filter = null) {}
264264

265265
/** @return ReflectionClassConstant[] */
266-
public function getReflectionConstants(int $filter = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE) {}
266+
public function getReflectionConstants(?int $filter = null) {}
267267

268268
/** @return mixed */
269269
public function getConstant(string $name) {}

ext/reflection/php_reflection_arginfo.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: f5f4cfeab0e81c2b51bf11dde7b7d40fc87d9cbc */
2+
* Stub hash: 4429ea0f96f81c3dbfb2a7e6e00ce49aea4bfeb1 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
@@ -195,11 +195,9 @@ ZEND_END_ARG_INFO()
195195

196196
#define arginfo_class_ReflectionClass_hasConstant arginfo_class_ReflectionClass_hasMethod
197197

198-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass_getConstants, 0, 0, 0)
199-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filter, IS_LONG, 0, "ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE")
200-
ZEND_END_ARG_INFO()
198+
#define arginfo_class_ReflectionClass_getConstants arginfo_class_ReflectionClass_getMethods
201199

202-
#define arginfo_class_ReflectionClass_getReflectionConstants arginfo_class_ReflectionClass_getConstants
200+
#define arginfo_class_ReflectionClass_getReflectionConstants arginfo_class_ReflectionClass_getMethods
203201

204202
#define arginfo_class_ReflectionClass_getConstant arginfo_class_ReflectionClass_hasMethod
205203

ext/reflection/tests/ReflectionClass_toString_001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String
166166
Method [ <internal:Reflection> public method getConstants ] {
167167

168168
- Parameters [1] {
169-
Parameter #0 [ <optional> int $filter = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE ]
169+
Parameter #0 [ <optional> ?int $filter = null ]
170170
}
171171
}
172172

173173
Method [ <internal:Reflection> public method getReflectionConstants ] {
174174

175175
- Parameters [1] {
176-
Parameter #0 [ <optional> int $filter = ReflectionClassConstant::IS_PUBLIC | ReflectionClassConstant::IS_PROTECTED | ReflectionClassConstant::IS_PRIVATE ]
176+
Parameter #0 [ <optional> ?int $filter = null ]
177177
}
178178
}
179179

0 commit comments

Comments
 (0)