Doc #76049 [Opn->Csd]: ReflectionParameter::__construct() accepts an array for $function
Edit report at https://bugs.php.net/bug.php?id=76049&edit=1
ID: 76049
Updated by: krakjoe@php.net
Reported by: benjamin dot morel at gmail dot com
Summary: ReflectionParameter::__construct() accepts an array
for $function
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Reflection related
Operating System: N/A
PHP Version: Irrelevant
-Assigned To:
+Assigned To: krakjoe
Block user comment: N
Private report: N
New Comment:
The documentation has been fixed.
Previous Comments:
------------------------------------------------------------------------
[2018-03-05 12:49:15] 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.
------------------------------------------------------------------------
[2018-03-05 12:25:45] requinix@php.net
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:11:54] 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
test($function);
---
What about callable|array then, with a note about acceptable arrays?
------------------------------------------------------------------------
[2018-03-05 11:27:39] requinix@php.net
Valid strings and arrays, \Closures, and objects with __invoke are supported.
"callable" would be the most appropriate type.
------------------------------------------------------------------------
[2018-03-05 11:12:47] benjamin dot morel at gmail dot com
Description:
------------
The ReflectionParameter constructor is documented as accepting a string only for the first
parameter:
http://php.net/manual/en/reflectionparameter.construct.php
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 )
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76049&edit=1
Thread (6 messages)