Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124468 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 43AF11A00B7 for ; Thu, 18 Jul 2024 09:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721295730; bh=73TrpQr6HcRjW1Wd+FmVbPhn3TmmUfVd1rPJFw1Vbbs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=leBsrMrA12u/9fpvxQ+1qOcLRTlQ0rUECy377MtdcEiYd0MGlnazrjsW72NrxHOyx 2biS+hC3HjkHNlAGgdIbMczM1TQeXEDmzpO/ZC+DXvsUEE1z8IplyG5V76UEH0k907 e5UreTPoPl7fAZEMS0ejj/I4WmvJFvwnrhZCcAzmIbSDe0c9Dd1kcYYiIXckcFYFK9 jNqGY9cCoGrY2GhszGIdzQsem0PkEzumnyufL7XmiuIl4uEVTRYGCK9DoCjM2bTmim eB1Ozl1uCgL5JcewTJOnv+3o7Zk5NGtme/NL3XnBanPEiukrf7chtGYb0vzuRUPZwF IpAK/rJ5VLTqw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CCB3118003F for ; Thu, 18 Jul 2024 09:42:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from forward500a.mail.yandex.net (forward500a.mail.yandex.net [178.154.239.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 18 Jul 2024 09:42:06 +0000 (UTC) Received: from mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net [IPv6:2a02:6b8:c29:f35c:0:640:c770:0]) by forward500a.mail.yandex.net (Yandex) with ESMTPS id E719261807 for ; Thu, 18 Jul 2024 12:40:32 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id VeFChL7b0Gk0-akRm1tUe; Thu, 18 Jul 2024 12:40:32 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=php.watch; s=mail; t=1721295632; bh=7Z1PDIWKEDtSRknaah2NDu3+GI0lmFEmrbwod66196A=; h=To:Subject:Message-ID:References:Date:From:In-Reply-To:Cc; b=Cnr/aVVi2xlmFrkitbWv2vJ4Jxme8UXL5XBMXaWDTTr5K6b4WIj1/DYrJY8OAk5Nx JlofR02M+4Li1/lOcDPELEBbug/UhP11zlYfZiVq9phlgTEAdXU39e7Nq8VsAGQh8w 4k1IvuoI7iZ6dEBALBUxNRWqtB2Xcr58yFoOQ3rQ= Authentication-Results: mail-nwsmtp-smtp-production-main-55.vla.yp-c.yandex.net; dkim=pass header.i=@php.watch Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a77e7420697so65257866b.1 for ; Thu, 18 Jul 2024 02:40:32 -0700 (PDT) X-Gm-Message-State: AOJu0YzNGbbFcas4gDJPxcR2xLHl1oDGTpWjaJ1YlgGPM2UwydVox24H xkLdO2VaxpTLPUN/hy6RW9kqfXgUPBBbSyAIS16dLCexM3TaOwA8Xg0Zp6GRFSpL+QzAUd0SdUc w5ftsCBl5ppSy0Kvt7jtx8eKdIOA= X-Google-Smtp-Source: AGHT+IGIcdLZ3WBB1HDkAOJ+ARzvQF4dNuupWm8ruA0/GvM8bmHWDBB72MzGvr7Z6r6DvSuEMxbfy/dCbaGjQxVLNhY= X-Received: by 2002:a17:906:3811:b0:a77:e55a:9e79 with SMTP id a640c23a62f3a-a7a0113fabfmr284564366b.4.1721295631664; Thu, 18 Jul 2024 02:40:31 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 18 Jul 2024 16:40:05 +0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PHP-DEV] Optional constructor body To: Oliver Nybroe Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: ayesh@php.watch (Ayesh Karunaratne) > > Hello internals. > > I am looking into making the constructor body optional in classes, essent= ially allowing you to write > > ``` > class User { > public function __construct( > private string $name, > ) > } > ``` > > Currently to make this code valid, it would have to be written the follow= ing way > > ``` > class User { > public function __construct( > public string $name, > ) {} > } > ``` > > With the introduction or constructor property promotion in 8.0, we often = see classes where the constructor has an empty body, and my guess would be = that this will only increase with the introduction of property access hooks= in 8.4 which is allowed to be defined in the constructor also. > > This change would only be a cosmetic change and simplify the userland cod= e by removing two redundant characters. > > > > This would be my first RFC and I am willing to try and implement it mysel= f. > > > Best regards > Oliver Nybroe (he/him) Hi Oliver, Some links to previous discussions when this was brought up in the mailing list before: - https://externals.io/message/114324 - https://externals.io/message/111590 I followed those discussions closely back then, and I suppose the general sentiment (to which I also agree) was that this is more of a code style consideration rather than a technical one. Although it's a cosmetic change, the fact that it will cause BC issues on older PHP versions was a significant concern; now more so after we had Constructor Properties for 4 years. I think you can gather more pre-RFC opinions from this mailing thread, especially now that this is brought up after a while since Constructor Properties were introduced. If you do with to go with an RFC, I'd like to see if your proposal addresses whether this syntax should implicitly call `parent::__construct()`, and if a semi colon is expected or not (`public function __construct(public int $foo);` vs `public function __construct(public int $foo)`). Ayesh.