Hi!
On 5 August 2014 18:01, Ralph Schindler <ra...@ralphschindler.com>
wrote: At the risk of stating the obvious, can’t you just use
$f->bar->__invoke()?
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.php
Interestingly, reflection doesn't even expose it:
http://3v4l.org/8Jutn
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?
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.
-ralph
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php