php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75186 Inconsistent reflection of Closure:::__invoke()
Submitted: 2017-09-11 12:37 UTC Modified: 2018-10-02 16:49 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:0 of 2 (0.0%)
From: kontakt at kukulich dot cz Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kontakt at kukulich dot cz
New email:
PHP Version: OS:

 

 [2017-09-11 12:37 UTC] kontakt at kukulich dot cz
Description:
------------
https://3v4l.org/QBIvb

Test script:
---------------
<?php

$rc = new ReflectionClass(Closure::class);

$methodNames = array_map(function ($m) {
   return $m->getName();
}, $rc->getMethods());

var_dump(in_array('__invoke', $methodNames));
var_dump($rc->hasMethod('__invoke'));

Expected result:
----------------
bool(true)
bool(true)

Actual result:
--------------
bool(false)
bool(true)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-07 16:02 UTC] carusogabriel34 at gmail dot com
Could not reproduced https://3v4l.org/mGJjd
 [2018-02-07 20:24 UTC] kontakt at kukulich dot cz
See the test in the description.
 [2018-02-28 20:08 UTC] carusogabriel34 at gmail dot com
From the documentation:
> 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.

So I believe is the expected behavior.
 [2018-10-02 16:49 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2018-10-02 16:49 UTC] nikic@php.net
It looks like we have a bunch of special-casing for Closure::__invoke, but getMethods() in particular only uses it if the reflection is on an object rather than class.
 [2019-05-09 10:36 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=35c80583f08c0af3d01715cb8feeca6d0f284545
Log: Fixed bug #75186
 [2019-05-09 10:36 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 10:01:27 2024 UTC