php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71622 Strings used in pass-as-reference cannot be used to invoke $callable()
Submitted: 2016-02-18 09:53 UTC Modified: 2016-02-18 12:08 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: mblarsen at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.3 OS: Ubuntu 14.04.4 LTS, Trusty Tahr
Private report: No CVE-ID: None
 [2016-02-18 09:53 UTC] 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. 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-18 12:08 UTC] danack@php.net
-Status: Open +Status: Verified
 [2016-02-18 12:08 UTC] danack@php.net
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();
 [2016-02-18 12:53 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3ce6ad9d1348f9603dfa59c4aa6f3135333f34b2
Log: Fixed bug #71622 (Strings used in pass-as-reference cannot be used to invoke C::$callable())
 [2016-02-18 12:53 UTC] bwoebi@php.net
-Status: Verified +Status: Closed
 [2016-02-18 12:54 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3ce6ad9d1348f9603dfa59c4aa6f3135333f34b2
Log: Fixed bug #71622 (Strings used in pass-as-reference cannot be used to invoke C::$callable())
 [2016-07-20 11:33 UTC] davey@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3ce6ad9d1348f9603dfa59c4aa6f3135333f34b2
Log: Fixed bug #71622 (Strings used in pass-as-reference cannot be used to invoke C::$callable())
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 00:01:28 2024 UTC