Skip to content

get_class_methods($closure) doesn't return __invoke #17126

@faizanakram99

Description

@faizanakram99

Description

The following code:

<?php

$closure = fn (string $str) => "hello {$str}";

print_r(get_class_methods($closure));

Resulted in this output:

Array
(
    [0] => bind
    [1] => bindTo
    [2] => call
    [3] => fromCallable
)

But I expected this output instead:

Array
(
    [0] => bind
    [1] => bindTo
    [2] => call
    [3] => fromCallable
    [4] => __invoke
)

__invoke does exist on Closures, it is documented too, see https://3v4l.org/VKjAF

From https://www.php.net/manual/en/class.closure.php

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.

PHP Version

8.2

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions