Bug #77627 [Ver]: method_exists returns false for Closure::__invoke

From: Date: Sat, 19 Oct 2019 20:09:15 +0000
Subject: Bug #77627 [Ver]: method_exists returns false for Closure::__invoke
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223308@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77627&edit=1

 ID:                 77627
 Updated by:         nikic@php.net
 Reported by:        marcospassos dot com at gmail dot com
 Summary:            method_exists returns false for Closure::__invoke
 Status:             Verified
 Type:               Bug
 Package:            Reflection related
 Operating System:   Mac OS
 PHP Version:        7.3.2
 Block user comment: N
 Private report:     N

 New Comment:

@maks dot feltrin at gmail dot com: Those results are correct, because __invoke is not a static
method. You can't actually call MyClass::__invoke(), only (new MyClass)->__invoke().

(method_exists works on different principles, so it should indeed return true.)


Previous Comments:
------------------------------------------------------------------------
[2019-10-19 19:12:36] maks dot feltrin at gmail dot com

I have similar issue with "__invoke()"

class MyClass {
    public function __invoke() {}
}

__invoke callability tests yield different results than any other public method.

is_callable(["MyClass", "__invoke"]) NOT-OK evaluates to FALSE, should be TRUE
is_callable(["MyClass::__invoke"]) NOT-OK evaluates to FALSE, should be TRUE
is_callable([new MyClass(), "__invoke"] OK

php 5.4 yields correct results, 5.5 to 7.3 do not.

------------------------------------------------------------------------
[2019-02-16 19:59:55] marcospassos dot com at gmail dot com

Description:
------------
The method_exists function returns false for Closure::__invoke.

According to the docs:
"Besides the methods listed here, this class also has an __invoke method. This is for
consistency with other classes that implement calling magic, as this method is not used for calling
the function."
Source: http://php.net/manual/en/class.closure.php

Test script:
---------------
https://3v4l.org/nIte4

Expected result:
----------------
true

Actual result:
--------------
false


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77627&edit=1


Thread (5 messages)

« previous php.bugs (#223308) next »