Re: [RFC] Primary Constructors
| From: | Tim Düsterhus | Date: | Mon, 29 Jun 2026 19:43:19 +0000 |
| Subject: | Re: [RFC] Primary Constructors | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131615@lists.php.net to get a copy of this message | ||
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: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üsterhusclass 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 = $xassignment 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.