Bug #69236 [NEW]: Static variable reported as not declared with __invoke() and splat operator

From: Date: Fri, 13 Mar 2015 06:29:50 +0000
Subject: Bug #69236 [NEW]: Static variable reported as not declared with __invoke() and splat operator
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191362@lists.php.net to get a copy of this message
From: sebastian Operating system: Irrelevant PHP version: 5.6.6 Package: Scripting Engine problem Bug Type: Bug Bug description:Static variable reported as not declared with __invoke() and splat operator 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 -- Edit bug report at https://bugs.php.net/bug.php?id=69236&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69236&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69236&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69236&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69236&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69236&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69236&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69236&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69236&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69236&r=support Expected behavior: https://bugs.php.net/fix.php?id=69236&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69236&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69236&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69236&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69236&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69236&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69236&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69236&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69236&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69236&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69236&r=mysqlcfg

« previous php.bugs (#191362) next »