Bug #77772 [Opn->Csd]: ReflectionClass::getMethods(null) doesn't work
| From: | nikic@php.net | Date: | Fri, 22 Mar 2019 11:41:50 +0000 |
| Subject: | Bug #77772 [Opn->Csd]: ReflectionClass::getMethods(null) doesn't work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220126@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77772&edit=1
ID: 77772
Updated by: nikic@php.net
Reported by: chokolatrix at gmail dot com
Summary: ReflectionClass::getMethods(null) doesn't work
-Status: Open
+Status: Closed
Type: Bug
Package: Reflection related
PHP Version: 7.2.16
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=da35fa2cb8d454c8e797067e28e647030a5fe5df
Log: Fixed bug #77772
Previous Comments:
------------------------------------------------------------------------
[2019-03-20 14:47:27] nikic@php.net
@danack: The optional parameter is not an array, but an integer. Currently null is interpreted as 0,
which means everything is filtered out. I agree with the reporter that null should behave the same
as not passing anything (i.e. no filter). I think we can safely make this change, as the current
behavior is not useful in any way, so I'm not particularly concerned about BC here.
------------------------------------------------------------------------
[2019-03-20 14:44:44] danack@php.net
Although the behaviour is not correct, passing null in place of an optional array parameter is not
going to give you the correct result.
The function should be giving an error when passing null as the behaviour of optional parameters in
internal functions should match that of userland functions:
ReflectionClass::getMethods(array $filter = []) {...}
------------------------------------------------------------------------
[2019-03-20 14:19:05] chokolatrix at gmail dot com
Description:
------------
---
From manual page: https://php.net/reflectionclass.getmethods
---
The function doesn't work as one would expect.
Passing NULL (no filter) as parameter returns an empty array instead of all the methods.
Test script:
---------------
function getClassMethods($FQCN, $methodFilter = null): array
{
foreach ((new \ReflectionClass($FQCN))->getMethods($methodFilter) as $methodObj) {
$methodsNames[] = $methodObj->name;
}
return $methodsNames ?? [];
}
var_dump(getClassMethods(\Iterator::class));
Expected result:
----------------
array:5 [
0 => "current"
1 => "next"
2 => "key"
3 => "valid"
4 => "rewind"
]
Actual result:
--------------
array(0) {
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77772&edit=1