Bug #77772 [Com]: ReflectionClass::getMethods(null) doesn't work

From: Date: Wed, 20 Mar 2019 14:44:44 +0000
Subject: Bug #77772 [Com]: ReflectionClass::getMethods(null) doesn't work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220099@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 Comment by: danack@php.net Reported by: chokolatrix at gmail dot com Summary: ReflectionClass::getMethods(null) doesn't work Status: Open Type: Bug Package: Reflection related PHP Version: 7.2.16 Block user comment: N Private report: N New Comment: 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 = []) {...} Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#220099) next »