|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77772 ReflectionClass::getMethods(null) doesn't work
Submitted: 2019-03-20 14:19 UTC Modified: 2019-03-20 14:47 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: chokolatrix at gmail dot com Assigned:
Status: Closed Package: Reflection related
PHP Version: 7.2.16 OS:
Private report: No CVE-ID: None
 [2019-03-20 14:19 UTC] chokolatrix at gmail dot com
From manual page:

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 ?? [];


Expected result:
array:5 [
  0 => "current"
  1 => "next"
  2 => "key"
  3 => "valid"
  4 => "rewind"

Actual result:
array(0) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-20 14:44 UTC]
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:47 UTC]
@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-22 11:41 UTC]
Automatic comment on behalf of
Log: Fixed bug #77772
 [2019-03-22 11:41 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 29 21:01:25 2023 UTC