-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Description
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