Re: Closure and $this

From: Date: Thu, 13 Jan 2011 06:57:53 +0000
Subject: Re: Closure and $this
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-310722@lists.php.net to get a copy of this message
On Wednesday, January 12, 2011 11:37:19 pm Greg Bair wrote: > On Wed, 12 Jan 2011 20:02:11 -0800 (PST) > > Raymond Irving <xwisdom@yahoo.com> 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 - > > http://raxanpdi.com > > Probably not, and my understanding of why comes from this line from the > docs (http://www.php.net/manual/en/functions.anonymous.php): > > "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: http://wiki.php.net/rfc/closures/object-extension --Larry Garfield

« previous php.general (#310722) next »