Re: Revisiting Anonymous Classes

From: Date: Sat, 28 Jun 2014 18:47:55 +0000
Subject: Re: Revisiting Anonymous Classes
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-75126@lists.php.net to get a copy of this message
On 28 Jun 2014, at 15:02, Thomas Bley <mails@thomasbley.de> wrote: > Hello Sebastian, > > for syntax consistency with anonymous functions I would prefer a longer Syntax: > > $greet = function ($name) { > printf("Hello %s\r\n", $name); > }; > $greet('World'); > > $log = class { > public function foo() {… > }; > $logObj = new $log(); I concur that I’d prefer this syntax. I also think it is much more obvious what it does; $x = new {} doesn’t make much sense unless you know of the feature, but $x = class {} isn’t much of a leap from class x {}. Furthermore, I think new {} could be better used for something else. Also, we could still have the class be immediately instantiated like so: $foo = new class Bar {}; Or, if the parser wouldn’t permit that: $foo = new (class Bar {}); Sebastian, do you agree with this? -- Andrea Faulds http://ajf.me/

« previous php.internals (#75126) next »