Re: Re: [RFC] [DISCUSSION]: Closure from callable
| From: | Stanislav Malyshev | Date: | Sun, 04 Oct 2015 19:50:13 +0000 |
| Subject: | Re: Re: [RFC] [DISCUSSION]: Closure from callable | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88668@lists.php.net to get a copy of this message | ||
Hi!
> I don't like that it's a function. Closure is a class, classes can have
> static and instance methods, and closure() looks like something that
> should be a method on Closure. In fact, it creates a closure, which a
> constructor would usually do. If we want to make it avoid duplication,
> okay, then it could be a static method. But I'm unconvinced it should be
> a function. Constructors go in their classes, we don't leave them lying
> around as global functions. That's messy and inconsistent.
Agree. Closure::fromCallable sounds like a good option.
That being said, I'm not sure how much need is for this - i.e. you can
always make a closure by just doing function() { return $this->blah(); }
if you need it. But the bigger question would be why you need more
specific type (Closure) instead of more generic (callable) and aren't
you overspecifying in that case?
And if we're into performance optimization - which should almost never
be done on language construct level, because performance considerations
vary and language constructs are forever - then it would be much better
to look into tail call optimizations. That would solve the barrier
between [$this, "foo"] and function() { return $this->foo(); } in many
practical cases.
--
Stas Malyshev
smalyshev@gmail.com