Re: Closures as methods (and Closure::bind)

From: Date: Thu, 12 Aug 2010 17:31:16 +0000
Subject: Re: Closures as methods (and Closure::bind)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-49429@lists.php.net to get a copy of this message
On Wed, 11 Aug 2010 14:57:47 +0100, Johannes Schlüter <johannes@schlueters.de> wrote:
On Wed, 2010-08-11 at 14:38 +0100, Gustavo Lopes wrote:
I've updated the wiki page for "Closures with objects extension" with things that are in "Proposal A with modification"s but are not implemented: http://wiki.php.net/rfc/closures/object-extension#status_as_of_august_10_2010 I propose an implementation of "closures stored in properties used as methods", as in: $this->prop = function () { ...} $this->prop();
[...] I don#t have an opinion on this feature, yet, I like the current class-based object model as reading code is relatively simple, with this addition (and the fact that you can create properties on the fly) we create a powerful tool for really hard to read code.
It's important to understand this is not mere syntactic sugar over $a = $this->prop; $a(); or call_user_func($this->prop). It actually allows executing closures in a way that fails if the staticness or bound instance of the closure is not what was expected. See the beautiful tree graphs on the wiki page. -- Gustavo Lopes

« previous php.internals (#49429) next »