Hi Nikita, I was thinking some more about your suggestion:
Nikita Popov wrote on 19/04/2016 15:18:
$foo = 42; return new class { private $bar = $foo; public function getBar() { return $this->bar; } }
If we allowed this, would it make sense to also allow it in named classes? This is currently illegal [https://3v4l.org/Kp0ep]:
$foo = 42; class X { private $bar = $foo; public function getBar() { return $this->bar; } }
It probably doesn't make sense to restrict this to specific expressions, so all of return new class { private $a = $var; private $b = $obj->prop; private $d = $obj->prop ?? 'default'; // ... } could be fine.
We don't allow importing expressions into closures, nor are any of those property initialisations valid in the definitions of named classes, so I think allowing them here would be odd.
Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php