Bug #76028 [Com]: call_user_func($a) and $a() behave differently

From: Date: Wed, 28 Feb 2018 14:38:40 +0000
Subject: Bug #76028 [Com]: call_user_func($a) and $a() behave differently
References: 1  Groups: php.standards 
Request: Send a blank email to standards-+get-1317@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76028&edit=1 ID: 76028 Comment by: bburnichon at gmail dot com Reported by: bburnichon at gmail dot com Summary: call_user_func($a) and $a() behave differently Status: Open Type: Bug Package: PHP Language Specification Operating System: Linux PHP Version: 5.6.33 Block user comment: N Private report: N New Comment: Checked versions having the issue with 3v4l.org: https://3v4l.org/Ssgep Previous Comments: ------------------------------------------------------------------------ [2018-02-28 14:33:43] bburnichon at gmail dot com Description: ------------ A callable can be defined as an array containing class and method. Calling call_user_func() with such an array has no issue. If you try to use the array as a callable, then 'self' loose its special meaning and an error is triggered saying class self does not exists. Test script: --------------- <?php class CallBySelf { public static function foo() { echo 'Foo', PHP_EOL; } public static function testCall() { $method = ['self', 'foo']; var_dump(is_callable($method)); echo 'Call via call_user_func: '; call_user_func($method); echo 'Direct call: '; $method(); } } CallBySelf::testCall(); Expected result: ---------------- Call via call_user_func: Foo Direct call: Foo Actual result: -------------- bool(true) Call via call_user_func: Foo Direct call: Fatal error: Class 'self' not found in /in/Ssgep on line 19 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76028&edit=1

« previous php.standards (#1317) next »