|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-03-20 14:19 UTC] 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) { } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 13:00:01 2025 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 = []) {...}