> On Sep 12, 2019, at 09:00, Michał Brzuchalski <michal.brzuchal...@gmail.com>
> wrote:
>
> Hi internals,
>
> I'd like to open discussion about RFC: Object Initializer.
>
> This proposal reduces boilerplate of object instantiation and properties
> initialization in case of classes without required constructor arguments as
> a single expression with initializer block.
>
> https://wiki.php.net/rfc/object-initializer
This reminds me of how Hack/HHVM would initialize object properties from
constructor parameters; I remember finding it very appealing.
IIRC, you would provide the property signature as a constructor parameter to
trigger the initialization:
```php
class Foo
{
protected int $bar;
public function __construct(protected int $bar)
{
}
public function getBar() : int
{
return $this->bar;
}
}
$foo = new Foo(1);
echo $foo->getBar(); // 1
```
Perhaps something like that is worth adopting here.
--
Paul M. Jones
pmjo...@pmjones.io
http://paul-m-jones.com
Modernizing Legacy Applications in PHP
https://leanpub.com/mlaphp
Solving the N+1 Problem in PHP
https://leanpub.com/sn1php
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php