php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77627 method_exists returns false for Closure::__invoke
Submitted: 2019-02-16 19:59 UTC Modified: 2019-10-19 20:09 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: marcospassos dot com at gmail dot com Assigned:
Status: Closed Package: Reflection related
PHP Version: 7.3.2 OS: Mac OS
Private report: No CVE-ID: None
 [2019-02-16 19:59 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-11 14:20 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2019-10-19 19:12 UTC] 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-10-19 20:09 UTC] nikic@php.net
@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.)
 [2021-05-25 09:23 UTC] git@php.net
Automatic comment on behalf of krakjoe
Revision: https://github.com/php/php-src/commit/cfd4d3df0bf6397b80108f6e2d144afbb55e0763
Log: Fix #77627 method_exists on Closure::__invoke
 [2021-05-25 09:23 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC