On Thu, Apr 13, 2023 at 3:47 PM Dan Ackroyd <dan...@basereality.com> wrote:
> I can't see a technical reason not to do it like this, but some people
> seem to be having negative gut reactions to it, and it's hard to
> persuade someone about aesthetics.
>
> Notes here: https://phpopendocs.com/rfc_codex/class_method_callable
>
> cheers
> Dan
> Ack

I'd be down for implementing this in a heartbeat if we can agree on a
syntax. I've run into this issue several times and have thought about
it, just never really done anything about it.

Hmm, yeah, looking at the implementation again, it may not be *that*
big of a change. If I'm understanding correctly, it *might* need a new
op-code (but could be done using the existing ZEND_CALLABLE_CONVERT),
but otherwise should be rather straightforward. The bigger changes are
going to be in the Callable implementation. As mentioned, this 'view
of the world' isn't really supported by the engine. You can't perform
this operation (calling a method on an interchangeable object) without
another closure (to my knowledge) to do so.

Perhaps we could sidestep the syntax issue by taking some inspiration
from Rowan(?) and just implement this as a method on \Closure or
\Callable, maybe something like this:

$a = Closure::fromCallable(static fn () => $this->getId());
$b = Closure::bindMany($items); // executes `bind` on each item in the
array, returning an array of closures
foreach($b as $callback) {
  $callback();
}

or something like that. My biggest thing is that there's no real way
to save much on typing this out. Unless you are doing something fairly
exotic, you only save a few characters. That's why I said its a lot of
work for not much benefit. I could be totally wrong though because I,
personally, do run into wanting this feature several times a year.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to