Re: RFC: Anonymous Class Lexical Scope

From: Date: Thu, 29 Dec 2016 16:59:26 +0000
Subject: Re: RFC: Anonymous Class Lexical Scope
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-97488@lists.php.net to get a copy of this message
Hi everyone, having worked a bit with anonymous classes these days, the current boilerplate is really high to inject some local context into them. So big +1 from me for the target. On the proposed syntax, I really prefer Nikita's proposal: return new class { > private $a = $var; > private $b = $obj->prop; > private $d = $obj->prop ?? 'default'; > // ... > } > The "functional equivalent" wording in the RFC has a big drawback: it looks like the parent constructor is overridden, which would be a really nasty side effect. It may not be the case in the implementation, but the the RFC needs to be clarified IMHO. If we were to need more closure-like syntax, we may even use "use" like this: return new class use ($var, $obj) { private $a = $var; private $b = $obj->prop; private $d = $obj->prop ?? 'default'; // ... } I really hope this new syntax (which ever raises the consensus) can be ready soon :) Nicolas

« previous php.internals (#97488) next »