Edit report at https://bugs.php.net/bug.php?id=65530&edit=1
ID: 65530 Updated by: requi...@php.net Reported by: matt dot minix at gmail dot com Summary: Anonymous functions not callable directly when part of a static class Status: Verified Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: 5.4 and later Block user comment: N Private report: N New Comment: It's ambiguous at compile time: Does "Class::$foo()" 1. As requested: execute the function stored in/referenced by Class::$foo 2. As currently: execute the static method in Class named according to the local $foo 3. Another possibility: evaluate the static property of Class whose name is returned by $foo() The only way I see to support more than one would be to resolve it at runtime, but even then it's still possible to write something that is legal all three ways: <?php class Ambiguous { public static $one; public static function two() { echo "two"; } public static $three = 3; } Ambiguous::$one = function() { echo "one"; }; function two() { echo "three"; return "three"; } $one = "two"; // 1. call_user_func(Ambiguous::$one) // 2. call_user_func("Ambiguous::" . $one) // 3. Ambiguous::${$one()} Ambiguous::$one(); ?> Looking at just the last line I'm not even sure what *I* would expect it to do... Previous Comments: ------------------------------------------------------------------------ [2013-08-26 09:51:28] yohg...@php.net PHP behaves as reported. It does not work 5.5 also. [yohgaki@dev PHP-5.5]$ ./sapi/cli/php <?php class a { public static $b; } a::$b = static function($c) { echo $c; }; a::$b('Test') ?> Fatal error: Function name must be a string in - on line 7 ------------------------------------------------------------------------ [2013-08-22 21:19:27] matt dot minix at gmail dot com Description: ------------ An anonymous function doesn't seem like it can be called directly when in a static class. Test script: --------------- class a { public static $b; } a::$b = static function($c) { echo $c; }; a::$b('Test'); I am however able to do class a { public static $b; } a::$b = static function($c) { echo $c; }; $Temp = a::$b; $Temp('Test'); Expected result: ---------------- "Test" Actual result: -------------- Fatal error: Function name must be a string ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65530&edit=1