|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76049 ReflectionParameter::__construct() accepts an array for $function
Submitted: 2018-03-05 11:12 UTC Modified: 2018-03-05 12:25 UTC
From: benjamin dot morel at gmail dot com Assigned:
Status: Open Package: Reflection related
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: benjamin dot morel at gmail dot com
New email:
PHP Version: OS:


 [2018-03-05 11:12 UTC] benjamin dot morel at gmail dot com
The ReflectionParameter constructor is documented as accepting a string only for the first parameter:

However, as mentioned in a comment on that page, it also accepts an array containing a class name and a method name.

Test script:
class Foo {
    function bar($baz) {}
$r = new ReflectionParameter(array('Foo', 'bar'), 'baz');
echo $r->getName();

Expected result:
public ReflectionParameter::__construct ( string|array $function , string $parameter )

Actual result:
public ReflectionParameter::__construct ( string $function , string $parameter )


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-05 11:27 UTC]
-Package: Documentation problem +Package: Reflection related
 [2018-03-05 11:27 UTC]
Valid strings and arrays, \Closures, and objects with __invoke are supported.

"callable" would be the most appropriate type.
 [2018-03-05 12:11 UTC] benjamin dot morel at gmail dot com
True, but it also accepts arrays representing private and non-static methods, which are not callable:


class Foo {
  private function bar($baz) {}

function test(callable $function) {}

$function = ['Foo', 'bar'];

// works as expected
echo (new \ReflectionParameter($function, 'baz'))->getName();

// Deprecated:  Non-static method Foo::bar() should not be called statically
// TypeError: Argument 1 passed to test() must be callable, array given


What about callable|array then, with a note about acceptable arrays?
 [2018-03-05 12:25 UTC]
I would keep "callable" and say that the $function doesn't have to be accessible by the calling scope.
If not that, "mixed" and explain in the parameters section.
 [2018-03-05 12:49 UTC] benjamin dot morel at gmail dot com
I'm afraid that callable is a bit misleading as it means something very precise in PHP, I'd go with mixed then.

The most important is to list exactly what types are allowed in the doc.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Dec 05 02:01:23 2020 UTC