Many thanks Larry.

I like the Closure::bind() method proposal.

Best regards
Do more with less -

--- On Thu, 1/13/11, Larry Garfield <> wrote:

From: Larry Garfield <>
Subject: Re: [PHP] Closure and $this
Date: Thursday, January 13, 2011, 1:57 AM

On Wednesday, January 12, 2011 11:37:19 pm Greg Bair wrote:
> On Wed, 12 Jan 2011 20:02:11 -0800 (PST)
> Raymond Irving <> wrote:
> > Hello,
> > Does anyone know if closures will ever support the $this keyword? 
> > I think it would be very useful when working with objects.
> > 
> > Best regards__RaymondDo more with less -
> Probably not, and my understanding of why comes from this line from the
> docs (
> "Anonymous functions are currently implemented using the Closure class."
> So, in other words, your closure does not belong to the class you
> declare it in, but the Closure class.
>  Thus, if it supported the $this variable, it would refer not to the
>  class you want, but instead to the Closure class.
> Just my understanding.  If it's not right, someone point it out.

Actually at one point early on they did support a $this, but the way it was 
bound to an object was half-assed and incomplete so it was removed entirely 
from 5.3.  The intent was to then properly think through how that binding 
should happen and re-introduce it properly in 5.4.  I believe a consensus was 
reached on how that should happen but I'm not sure what its implementation 
status is at present.

I believe this is the relevant RFC:

--Larry Garfield

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to