Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124504 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 0E0F91A00B7 for ; Thu, 18 Jul 2024 23:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721345986; bh=pUD2yqY/aaei+VVwsUH9cT7vB+vHJnwoz5TgAkuYBew=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XjL9sfzQ5Jhs/Ec53aTbLCSDCJe73EDXLOdFUV9lfBQ/dziyPK+b45pBv30hcWxbL 9NLqwfnf5fWu3wIfsMMykaqfOXuKrp8biWcJkOSkHN2Kf5iC9/FB9+0ptLTRP7nLG/ HxW5LlH/riSlDF7oDQj9ZD05lhY0PyYDyo0Mv4PUIoAA3E1AR39HPNylXB6CW6Q1S9 zoQhxgRwk3o88Q/8q9QcX5W18R4f6lV4vMxQQo3CUTlkhNDRNC8fAW1xDuYDHjYezn 5HRU1a1ZIMROCGUmA9/c4d8iiKjVxDmGm0GTkcwtOhlTNlnKlQxyHmdCwX7bBMT8T8 pyQ/EsS2NfEBg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 16B7B180614 for ; Thu, 18 Jul 2024 23:39:46 +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=1.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_INVALID,DKIM_SIGNED,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 18 Jul 2024 23:39:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1721345891; cv=none; d=zohomail.com; s=zohoarc; b=MTMM4QwQS5d51s0IRkv4HbVLelF0HqxlFkIKuRf8WOE3bhg9+iW+a14yFESkR5wxeIxeN8jsu+CNmjaiQOyeayPFebOkK1v0XKIZn+vwhcOE2WrGvDzp6jBOgp9lXMGdpEA9tAK+u7g+4vUFqRdT1PeJSXvA/ACzM0Koof1pFWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721345891; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=0fQshv3DN62g2vBEdf/L9T9jx3y+6ExOH+J8PbTR5GA=; b=X/x5vTJlfqNkjgSGbnH6aUk3IUjRZnaTOnorDra4bjZuEpxopDk5OyWOoYM6+NlUGTiyuUkL8rAST2FgeuL8hrX1AC2L0cCP5vYOF/4wtyg1vWIiWQwB/ECKRCR1C6EwjTANSCUH1+HVGsNBK7bV7o0lLYRYHmOhRho1x+q0uks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=faizanakram.me; spf=pass smtp.mailfrom=hello@faizanakram.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1721345891; s=zoho; d=faizanakram.me; i=hello@faizanakram.me; h=MIME-Version:References:In-Reply-To:From:From:Date:Date:Message-ID:Subject:Subject:To:To:Cc:Cc:Content-Type:Message-Id:Reply-To; bh=0fQshv3DN62g2vBEdf/L9T9jx3y+6ExOH+J8PbTR5GA=; b=DL4Hm3D55iMJ3M7G1YgGBGqSl7qjxAY9z6U7dw9WzM6XTRpauyWnyzn9RAD5inWI meKSh6NJXH0DPgb8SHtDofUOhe26Q3FU/4KJ4blHuO2yJafkMxC9TcVgnascaIcr6EK LyXmz6Zx2WkTe1qWOxCV27vP1qwJBRf4iIlSNM64= Received: by mx.zohomail.com with SMTPS id 17213458909901012.7655583731919; Thu, 18 Jul 2024 16:38:10 -0700 (PDT) Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e05e2b2d88bso1397557276.0 for ; Thu, 18 Jul 2024 16:38:10 -0700 (PDT) X-Gm-Message-State: AOJu0YwGey+GNubhENIFEVCS80KQbZJtVC2SfjtZquZGMuSFU+pq05zS aGOjF5Sx7ugWpndPuqhqVawB2FSMuewiHpq9HQR/PhKp/sMn+kS24UzKdeg3jdHX2jNaN6jgBNo 6+S/T2q1sZy/GV7JwYLwHamz8elE= X-Google-Smtp-Source: AGHT+IE7lTH184slr8YOTV+ekLJK5YUj8og5yCgF0dCYh81+887zNJVoWzFsWk5QhK6Ac7+OZKDtopvsCK0XNpk4Low= X-Received: by 2002:a05:6902:218e:b0:e03:5897:770e with SMTP id 3f1490d57ef6-e08609710bfmr442334276.27.1721345890279; Thu, 18 Jul 2024 16:38:10 -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: Fri, 19 Jul 2024 01:37:59 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PHP-DEV] Optional constructor body To: Oliver Nybroe Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000537311061d8e121d" X-ZohoMailClient: External From: hello@faizanakram.me (Faizan Akram Dar) --000000000000537311061d8e121d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jul 19, 2024 at 1:34=E2=80=AFAM Oliver Nybroe wrote: > Hello internals. > > I am looking into making the constructor body optional in classes, > essentially 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 > following 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 b= e > that this will only increase with the introduction of property access hoo= ks > 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 > myself. > > > Best regards > Oliver Nybroe (he/him) > FWIW, there is already a PR for it ( https://github.com/php/php-src/issues/8420) which also contains the RFC draft. Kind regards, Faizan --000000000000537311061d8e121d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Jul 19, 2024 at 1:34=E2=80=AF= AM Oliver Nybroe <olivernybroe= @gmail.com> wrote:
Hello internals.=C2=A0

I am looking= into making the constructor body optional in classes, essentially allowing= you to write

```
class User {
=C2=A0= =C2=A0 public function __construct(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 private= string $name,
=C2=A0 =C2=A0 )
}
```

Curr= ently to make this code valid, it would have to be written the following wa= y

```
class User {
=C2=A0 =C2=A0 public function __construct(<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 public string $name,
=C2=A0 =C2=A0 ) {}}
```

With the introduction or constructor pr= operty 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 int= roduction of property access hooks in 8.4 which is allowed to be defined in= the constructor also.=C2=A0

This change would only be a cosmetic ch= ange and simplify the userland code by removing two redundant characters.= =C2=A0



This would be my fir= st RFC and I am willing to try and implement it myself.=C2=A0

Best regards
Oliver Nybroe (he/him)


FWIW, there is alr= eady a PR for it (ht= tps://github.com/php/php-src/issues/8420) which also contains the RFC d= raft.

Kind regards,
Faizan
=C2=A0
--000000000000537311061d8e121d--