|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73118 is_callable callable name reports misleading value for anonymous classes
Submitted: 2016-09-20 04:58 UTC Modified: 2016-09-20 05:07 UTC
From: nihylum at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 7.0.11 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: nihylum at gmail dot com
New email:
PHP Version: OS:


 [2016-09-20 04:58 UTC] nihylum at gmail dot com
Tested on:
- PHP 7.0.8 ( )
- 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:

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:

trait callback {
  public function __invoke($who)
    return 'hello world';

class foo { use callback; }

$inline = new class { use callback; };

  is_callable($inline, false, $target),
  is_callable([$inline, '__invoke'], false, $target),
  is_callable(new foo, false, $target),

Expected result:
string(15) "class@anonymous"
string(15) "class@anonymous"
string(13) "foo::__invoke"

Actual result:
Solution 1:

string(15) "class@anonymous::__invoke"
string(15) "class@anonymous::__invoke"
string(13) "foo::__invoke"

Solution 2:

string(15) "[000000003cc480c70000000035210066]::__invoke"
string(15) "[000000003cc480c70000000035210066]::__invoke"
string(13) "foo::__invoke"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-20 05:07 UTC] nihylum at gmail dot com
Well, i was sure i targeted the correct boxes for expected and actual result (at this bug report currently interchanged). Sorry, my bad. :/
 [2017-02-11 23:16 UTC]
Automatic comment on behalf of as
Log: Fixed bug #73118
 [2017-02-11 23:16 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jun 01 09:01:28 2020 UTC