Re: [PHP-DEV] [RFC] Primary Constructors

[email protected] (Tim Düsterhus)
Newsgroups php.internals
Message-ID <[email protected]>
Hi

Am 2026-06-29 21:21, schrieb Seifeddine Gmati:
> I don't think the "seek to the constructor" problem is real in 
> practice.
> By convention the constructor goes first in a PHP class, so the code
> you'd be reading is simply:
> 
> ```
> class Foo extends Base
> {
>   public function __construct(public int $a, public string $b)
>   {
>     parent::__construct($a, $b);
>   }
> }
> ```
> 
> That's seven lines that fit comfortably on any screen, and each 
> concept,
> the class, the constructor, the promoted properties, the parent call,
> sits on its own line where it's immediately recognizable. Packing all 
> of
> it onto a single line saves nothing and makes the code harder to read,
> not easier.
> 
> I also disagree with comparing this to promoted properties. Promoted
> properties removed genuine boilerplate: the property declaration, the
> constructor parameter, and the `$this->x = $x` assignment collapsed 
> into
> one place because they were the same information repeated three times.
> Primary constructors don't remove repetition; they just relocate the
> constructor signature into the class declaration line. There's no
> duplicated information being eliminated.

And even though I just argued in favor of the current proposal in a 
reply to Nick (https://news-web.php.net/php.internals/131614), I also 
agree with Seifeddine, that I don’t think that the value provided by 
this proposal is sufficiently strong to get a “Yes” from me - but I know 
that allowing arbitrary bodies would be a “No”.

Best regards
Tim Düsterhus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.