Bug #69236 [Opn->Nab]: Static variable reported as not declared with __invoke() and splat operator

From: Date: Fri, 13 Mar 2015 06:55:24 +0000
Subject: Bug #69236 [Opn->Nab]: Static variable reported as not declared with __invoke() and splat operator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191363@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69236&edit=1 ID: 69236 Updated by: datibbaw@php.net Reported by: sebastian@php.net Summary: Static variable reported as not declared with __invoke() and splat operator -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Irrelevant PHP Version: 5.6.6 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php The "Uniform variable syntax" change wasn't back ported to 5.6: https://github.com/php/php-src/pull/686 Therefore the following interpretation applies: Foo::$bar['baz']() -> Foo::{$bar['baz']}() Previous Comments: ------------------------------------------------------------------------ [2015-03-13 06:29:49] sebastian@php.net 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 this bug report at https://bugs.php.net/bug.php?id=69236&edit=1

« previous php.bugs (#191363) next »