Many thanks Larry. I like the Closure::bind() method proposal.
Best regards __ Raymond Do more with less - http://raxanpdi.com --- On Thu, 1/13/11, Larry Garfield <la...@garfieldtech.com> wrote: From: Larry Garfield <la...@garfieldtech.com> Subject: Re: [PHP] Closure and $this To: email@example.com 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 <xwis...@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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php