Bug #71622 [Ver->Csd]: Strings used in pass-as-reference cannot be used to invoke $callable()
Edit report at https://bugs.php.net/bug.php?id=71622&edit=1
ID: 71622
Updated by: bwoebi@php.net
Reported by: mblarsen at gmail dot com
Summary: Strings used in pass-as-reference cannot be used to
invoke $callable()
-Status: Verified
+Status: Closed
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:
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())
Previous Comments:
------------------------------------------------------------------------
[2016-02-18 12:08:11] 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 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)