|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-03-13 06:55 UTC] datibbaw@php.net
-Status: Open
+Status: Not a bug
[2015-03-13 06:55 UTC] datibbaw@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 17:00:02 2026 UTC |
Description: ------------ Using self::$invokables[$method](...$arguments); where self::$invokables is an array of objects that implement __invoke() does not work. PHP wrongly complains that self::$invokables is not declared. Test script: --------------- <?php class c { private static $invokables = []; public static function registerInvokable($name, $invokable) { self::$invokables[$name] = $invokable; } public function __call($method, array $arguments) { // works $method = self::$invokables[$method]; $method(...$arguments); // does not work self::$invokables[$method](...$arguments); } } class i { public function __invoke(...$arguments) { print_r($arguments); } } c::registerInvokable('foo', new i); $c = new c; $c->foo(1, 2); Expected result: ---------------- Array ( [0] => 1 [1] => 2 ) Array ( [0] => 1 [1] => 2 ) Actual result: -------------- Array ( [0] => 1 [1] => 2 ) Notice: Undefined variable: invokables in /home/sb/test.php on line 18 Fatal error: Function name must be a string in /home/sb/test.php on line 18