php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69236 Static variable reported as not declared with __invoke() and splat operator
Submitted: 2015-03-13 06:29 UTC Modified: 2015-03-13 06:55 UTC
From: sebastian@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.6.6 OS: Irrelevant
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sebastian@php.net
New email:
PHP Version: OS:

 

 [2015-03-13 06:29 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-13 06:55 UTC] datibbaw@php.net
-Status: Open +Status: Not a bug
 [2015-03-13 06:55 UTC] datibbaw@php.net
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']}()
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 09:00:02 2026 UTC