Bug #71622 [Opn->Ver]: Strings used in pass-as-reference cannot be used to invoke $callable()

From: Date: Thu, 18 Feb 2016 12:08:15 +0000
Subject: Bug #71622 [Opn->Ver]: Strings used in pass-as-reference cannot be used to invoke $callable()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199318@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71622&edit=1

 ID:                 71622
 Updated by:         danack@php.net
 Reported by:        mblarsen at gmail dot com
 Summary:            Strings used in pass-as-reference cannot be used to
                     invoke $callable()
-Status:             Open
+Status:             Verified
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Ubuntu 14.04.4 LTS, Trusty Tahr
 PHP Version:        7.0.3
 Block user comment: N
 Private report:     N

 New Comment:

Reproduce case for posterity:


function getMethodName(&$methodName) {
    $methodName = Abc::METHOD_NAME;
}

class Abc {

    const METHOD_NAME = "goal";

    private static function goal() {
        echo "success", PHP_EOL;
    }

    public static function run()
    {
        $method = "foobar";
        getMethodName($method);
        printf(
            "isCallable(self::%s) is %d\n",
            $method,
            is_callable("self::$method")
        );
        self::$method();
    }
}

Abc::run();


Previous Comments:
------------------------------------------------------------------------
[2016-02-18 09:53:24] mblarsen at gmail dot com

Description:
------------
If you pass a string-variable to a method that accepts the variable by reference, then the same
variable in the calling context no longer behaves like a normal string when it comes to invoking
callables on self:: (and like other contexts) but instead produces the error: Function
name must be a string, despite the variable is a valid string.

The test script below show different cases. Notably is the last case where the value of the
"damaged" variable is passed to a new variable to achieve the desired result with success,
thus the content is fine, but the variable is "damaged".

Test script:
---------------
http://sandbox.onlinephpfunctions.com/code/5fa7c924f4e8514d6020b180decd96e5969d4014

In the linked sandbox you can see that it works in 5.6.x but not in either of the released 7
versions: 7.0.3, 7.0.1, etc.

Expected result:
----------------
Test scripts shows the bug under difference circumstances. 



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71622&edit=1


Thread (3 messages)

« previous php.bugs (#199318) next »