Bug #68475 [Com]: call_user_func($a) not equivalent to $a()
| From: | nicolas dot grekas+php at gmail dot com | Date: | Mon, 01 Dec 2014 07:10:36 +0000 |
| Subject: | Bug #68475 [Com]: call_user_func($a) not equivalent to $a() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188869@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68475&edit=1
ID: 68475
Comment by: nicolas dot grekas+php at gmail dot com
Reported by: nicolas dot grekas+php at gmail dot com
Summary: call_user_func($a) not equivalent to $a()
Status: Assigned
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.6.3
Assigned To: jpauli
Block user comment: N
Private report: N
New Comment:
This check for double double colons is implemented for the callable type hint.
This means that the performance argument is not relevant (since a type hint is checked as often if
not more often than a callable is effectivelly called).
More importantly, it means that the type hint is useless in the general case, since it gives no
guarantee whatsoever when the
$callable() syntax is used instead of the
call_user_func($callable) one.
Last but not least, making $callable() not an equivalent for
call_user_func($callable) just because of this case is a blocker for deprecating the
former, since there will always be a valid use case for it.
Especially since most of the code out there uses call_user_func($callable), because of
history.
Previous Comments:
------------------------------------------------------------------------
[2014-12-01 03:39:17] laruence@php.net
for the record, they are never guaranteed to be act the same.
and, there is voice to deprecated call_user_** at all.
so I don't think the fix is worthy to do (slowdown the fast path) ..
thanks
------------------------------------------------------------------------
[2014-12-01 03:39:16] laruence@php.net
for the record, they are never guaranteed to be act the same.
and, there is voice to deprecated call_user_** at all.
so I don't think the fix is worthy to do (slowdown the fast path) ..
thanks
------------------------------------------------------------------------
[2014-11-29 12:51:50] jpauli@php.net
Started a work at https://github.com/jpauli/php-src/compare/fix-68475
------------------------------------------------------------------------
[2014-11-21 19:48:11] nicolas dot grekas+php at gmail dot com
Description:
------------
Since php5.4, call_user_func($a) is almost equivalent to $a()
$a() works with all callables BUT ONE.
A "foo::bar" string is OK for call_user_func(), but KO for pure syntax.
This make the new (and more performant) syntax useless in generic code that want to accept any
callable.
Test script:
---------------
<?php
class foo{static function bar(){}}
$a = 'foo::bar';
echo is_callable($a),"\n";
call_user_func($a);
$a();
Expected result:
----------------
1
Actual result:
--------------
1
Fatal error: Call to undefined function foo::bar() in ... on line 7
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68475&edit=1