I will +1 this as I have had to deal with some of these struggles, as a
suggestion though:

"Like the bind(To) methods, a static class cannot be bound (using →call
will fail)"

I would like to see this function work like
Closure::bind()/Closure::bindTo() and give the option for the $newScope
option.

> why would you need a closure that is not static,
> but is not bound to any object?

I think I can answer this, I wrote a project which allows for "hooks" to be
installed in areas of the code. I made it so each [static] method has a
"before" and "after" which may be tied to it. This allows for things like:
"beforeUpdate()" or "afterUpdate" or "afterCreate" exc... The framework
handled the installation and execution of all hooks that a dev may have
wished to install. If a method like this was available it would use much
less resources and be faster in theory because the PHP engine would not
need to create an entirely new object/closure every time I wished to
execute the method.

Simple example of what I spoke of above:
https://gist.github.com/allada/b7e880104e3a7eb13a63

Notice how you don't need to create an entirely new object just to call a
method inside a scope. This allows a dev to make their closure have access
to $this just as if it was installed inside the function it's hooking into.


On Mon, Aug 18, 2014 at 7:04 PM, Andrea Faulds <a...@ajf.me> wrote:

>
> On 18 Aug 2014, at 00:40, Levi Morrison <le...@php.net> wrote:
>
> > On Sun, Aug 17, 2014 at 5:13 PM, Stas Malyshev <smalys...@sugarcrm.com>
> wrote:
> >> Hi!
> >>
> >>> It does, but maybe you missed it. Under the Proposal section:
> >>>
> >>>> To solve this, we relax the current invariant of scoped closures
> >>>> having to be bound, and add a new parameter to bind(To) to produce
> >>>> an unbound, scoped closure, like so:
> >>
> >> Indeed, I missed it - I was looking for bindTo. I think it should be
> >> made more prominent, and I'm not sure what closure that is not static,
> >> but does not have a bound object, means. What happens if you call it? It
> >> sounds a bit strange concept - why would you need a closure that is not
> >> static, but is not bound to any object?
> >
> > Hence the vote was cancelled while it is reworked.
>
> To clarify: The RFC has been reworked now, I actually changed the RFC and
> patch just before I cancelled the vote. Review appreciated before vote is
> reopened.
>
> --
> Andrea Faulds
> http://ajf.me/
>
>
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to