On Wed, Jun 1, 2016 at 7:49 PM, Peter Cowburn <petercowb...@gmail.com> wrote:
> > While it's not as concise as your example, anonymous classes can do this > already after a fashion. > > $this->fooMethod( > $arg1, > $arg2, > new class() extends FooParams { > // Constructor because prop3's value isn't a constant expression > function __construct() { > $this->prop1 = '...'; > $this->prop2 = '...'; > $this->prop3 = new class() extends Obj1 { > public $prop1 = '...'; > public $prop2 = '...'; > }; > } > } > ); > > While that does avoid the temporary variable it seems more verbose than the temporary variable was to start with, even more so if you want to use variables from the outer context, since you have to thread them through the constructor. It also seems excessive adding a whole new (anonymous) class to the runtime just to avoid a temporary variable, but maybe that doesn't matter.