Bug #73118 [NEW]: is_callable callable name reports misleading value for anonymous classes
| From: | nihylum at gmail dot com | Date: | Tue, 20 Sep 2016 04:59:03 +0000 |
| Subject: | Bug #73118 [NEW]: is_callable callable name reports misleading value for anonymous classes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-204140@lists.php.net to get a copy of this message | ||
From: nihylum at gmail dot com
Operating system: any
PHP version: 7.0.11
Package: Class/Object related
Bug Type: Bug
Bug description:is_callable callable name reports misleading value for anonymous classes
Description:
------------
Tested on:
- PHP 7.0.8 ( eval.in )
- PHP 7.1.0beta3 via brew (OSX)
Whenever you analyze a callable that is defined by an anonymous class
the callable name remains to be "class@anonymous" instead of the real
callable name.
Solution 1:
Modify the callable name construction for anonymous classes to this
pattern:
class@anonymous::<method>
Solution 2:
Attach a 4th parameter $resolveAnonymous (that defaults maybe to true,
or false for backward compatibility). If set to true each anonymous
class and closures will be automatically resolved to its object hash
enclosed into box brackets as the class name part of the callable name
value (the brackets because of pattern isolation from real class
names).
Solution 3 (my favorite):
Solution 1 + 2 combined.
Test script:
---------------
<?php
trait callback {
public function __invoke($who)
{
return 'hello world';
}
}
class foo { use callback; }
$inline = new class { use callback; };
var_dump(
is_callable($inline, false, $target),
$target,
is_callable([$inline, '__invoke'], false, $target),
$target,
is_callable(new foo, false, $target),
$target
);
Expected result:
----------------
bool(true)
string(15) "class@anonymous"
bool(true)
string(15) "class@anonymous"
bool(true)
string(13) "foo::__invoke"
Actual result:
--------------
Solution 1:
bool(true)
string(15) "class@anonymous::__invoke"
bool(true)
string(15) "class@anonymous::__invoke"
bool(true)
string(13) "foo::__invoke"
Solution 2:
bool(true)
string(15) "[000000003cc480c70000000035210066]::__invoke"
bool(true)
string(15) "[000000003cc480c70000000035210066]::__invoke"
bool(true)
string(13) "foo::__invoke"
--
Edit bug report at https://bugs.php.net/bug.php?id=73118&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73118&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73118&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73118&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73118&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73118&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73118&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73118&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73118&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73118&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73118&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73118&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73118&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73118&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73118&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73118&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73118&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73118&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73118&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73118&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73118&r=mysqlcfg