On Mon, May 11, 2020 at 5:26 PM Dan Ackroyd <dan...@basereality.com> wrote:

> On Mon, 11 May 2020 at 10:52, Nikita Popov <nikita....@gmail.com> wrote:
> >
> > Please tell me if you have further concerns
>
> Question - as this is just sugar, presumably it doesn't add much
> complexity to the PHP engine?
>

Yes, the implementation complexity for this feature is minimal, as these
things go.


> Vague concern - because it's a novel syntax, I find it hard to read,
> particularly when there are comments* for the properties. Do you think
> I'll just get used to it, or is it likely to be an ongoing issue?
>

Well, I can't really answer this with confidence, but given the number of
people who told me how much they love this feature in TypeScript, I would
hazard that you would indeed get used to it.


> Also, in five years time, if we have structs**, people will be
> wondering why we bothered with this. But I think it does make life
> easier for developers in the meantime.
>

When we discussed this topic in chat last time, I got the feeling that the
rough consensus was that introducing "structs" as a feature distinct from
classes is a bad idea, and we should instead try to make relevant features
available for classes. Constructor promotion is one of those :)


> class UrlToPdfProcessor
> {
>     public function __construct(
>         // The full url to reach the instance of chrome running in
> headless mode.
>         public string $chromeUrl,
>
>         // A path to a directory where the output PDF will be written to.
>         // It must already exist and be writeable by the process running
>         // the PDF processor.
>         public string $tmpPath,
>
>         // The internal domain name for the site to be rendered.
>         // The domain name should not contain either protocol or path
>         // components
>         string $internalDomain
> ) {
>     }
> }
>

As suggested in
https://wiki.php.net/rfc/constructor_promotion#coding_style_considerations,
my recommendation is to use normal @param annotations for constructor
arguments, as we do now. While interleaving parameters and comments is
certainly possible (already), it's certainly not common style, and I don't
think it will become common style with constructor promotion.

Regards,
Nikita

Reply via email to