Re: [RFC] Closure::call and Function Referencing as Closures
| From: | Ralph Schindler | Date: | Wed, 06 Aug 2014 15:01:25 +0000 |
| Subject: | Re: [RFC] Closure::call and Function Referencing as Closures | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-76396@lists.php.net to get a copy of this message | ||
Hi!
When you put it like this, that further enhances my argument for adding a call() and/or a bindCall(). Having to rely on __invoke() means you're coding around and relying on an implementation detail, as opposed to the class's published API. It would be nice to be able to call closure in an object oriented way, in addition to the language-level call $func() and the functional/procedural way to call it call_user_func($func), after all, at current it seems OO-isms are more rampant in PHP than other programming paradigms. I realize that the whole concept of \Closure class was an "implementation detail" from the start (5.3), but that changed in 5.4 with the addition of the bind api, and the removal of the "don't rely on this type" text in the documentation. -ralphOn 5 August 2014 18:01, Ralph Schindler <ralph@ralphschindler.com> wrote: At the risk of stating the obvious, can’t you just use $f->bar->__invoke()?Side note, but that’s because __invoke on Closure doesn’t actually exist. It’s a method that is created by trying to access it and ceases to exist once called. Freaky, right?Actually, it was not immediately obvious that __invoke() was a method from the docs as it is a side-note and not in the class signature breakout. Oops! ;)http://php.net/manual/en/class.closure.phpInterestingly, reflection doesn't even expose it: http://3v4l.org/8Jutn