Hi Paul,

niedz., 15 wrz 2019 o 15:48 Paul M. Jones <pmjo...@pmjones.io> napisał(a):

>
>
> > 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.
>

What you're describing AFAIR was called "constructor argument promotion"
and this is not kind of problem current RFC tries to solve.
Argument promotion looks useful for constructors, in the name of good
practice constructors and methods|functions in general
should not require a lot of arguments.

Thank you for your feedback but I believe the suggested solution is
off-topic.

Thanks,
Michał Brzuchalski

Reply via email to