On 13 April 2023 04:59:56 BST, Eugene Sidelnyk <[email protected]> wrote:
>It would be a great pleasure to have the ability to wrap the instance >method the same way. The first-class callable syntax works just fine with instance methods, but you need to use it on a particular instance: $someInstance->someMethod(...) Unfortunately, this is no use for your example, essentially because PHP (unlike, say, Python) doesn't consider $this to be part of the parameters to a method: Verification::getId(...) would mean fn($item) => Verification::getId($item) but you can't call an instance method that way. What you want is fn($item) => $item->getId(). A syntax like ...->getId() wouldn't be much use - it wouldn't be able to check for the method's existence in advance (the "call to non-static" error in your example happens as soon as you try to create the closure https://3v4l.org/G8va8), or copy over any type information, because there's no way to deduce what class will be used later. So maybe it would need some other indicator, like Verification::getId(instance ...) to indicate that you want a closure with an extra parameter to be used as the instance. Maybe someone has a less ugly suggestion? Regards, -- Rowan Tommins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php
