Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126909 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 6386B1A00BC for ; Sun, 23 Mar 2025 11:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742728756; bh=2XZS3hTDWaBqInhBQoo5GC/44HMUdEEBMQcVPChJtQw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=U6w2+aqwNySBZ/9YC7TmDQ6HYsioM/Zx19qn8L1xa0v6hHnuKA863osb6zZABnsoJ 2VMZaB+o6AK8Z7sHrM8dsdVJ5mEHnUfAQZg2fql8WSNpWZy0noUum0fhGYqF405gwB aZfJNfMAMil1KJ/E7EzbILDs5J1UOqwITn2eyaYaQvAcgVo4W12pzZuCWXfBZ1u1WH 2igPNBeMA7XTh9XHrxs/z57nNbRpWZV8EjMdzXcmebaTDD8BFT4yqNwdutuCMDA/1A SF9C6o+5FWPmELeHW2HuJKWaQsMKb28FxBwzWNFUKk8IAdncQJ7bz0s7sJaWocMTFn O4v83fLPpivQA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6C45A18006A for ; Sun, 23 Mar 2025 11:19:15 +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=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, 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 mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 ; Sun, 23 Mar 2025 11:19:15 +0000 (UTC) Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-700b17551cdso30523117b3.0 for ; Sun, 23 Mar 2025 04:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742728904; x=1743333704; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SsEtpQskgj8Z+Q19oj4Kkntp2qa8GteAAxj+P6lfBas=; b=Lu7QTvkGd1kvmqUtEdmD/h0y6AAfLyzSm6lc1AYmgMLu7JFyec/d9CxjOaqp6D59dF St5qlyQERu/nYQryJjoXRLaX5vxr84trY5EzVua3eesmeMoNVnF2ObQ494r8C9ytZXcd lXBGlPzIJJHttwmSx9/x+dX5TuYg0A1u8jbkkzind7Nbe2c6OrNLi2skMO26sYp4DPtf c8i8HDV2DV73zld7zIjyM2BawZJ5zCFCrZ8bZB48IStJ/1HiNjAE1iBeZPcomLxVUjw1 +eWBKvSj0Q5vvoNh4E/tLxGj9cGsNxz4/C5o5HurLqtFc/7t4LAsecnL6ChcNQfngkqh 8org== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742728904; x=1743333704; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SsEtpQskgj8Z+Q19oj4Kkntp2qa8GteAAxj+P6lfBas=; b=bFTfvoiEOJZ039NEMUCLLxGgqlBFXnlkWH1dv4M1OgLTbgndAapIestzXzshn/bbot 4rmpsYopPilKWnLWb1a3Mt16iNZq7I0zU+elDPRz2GdRKoazEsTV2TUhROy42JGhMyU7 LodVolzr7Z8DToAw/4UF2B5oNC4JCAeYCkyIghly9bWeEhHl8xaPAU6/yU52pFAtDV3A corXCdJiGCiG1utZKNZCutH3WH0SHKo0J/4bC0fLINdYBBSOWHkyzA3uR03NFTQdau41 SqAq29RyYa3ycwBDORyDOwayUR8RkEhQ7sXoYLgCFrZ4lA7AMLPS4el9Y259GNLnVsOL 8Chg== X-Forwarded-Encrypted: i=1; AJvYcCUm6Uk3kJrfhoTU3SkWEOfVaJjlZZuhMLethG+jAfQT//Qf4huv77wrejcoTpCDFtxjLzY9B7sqfJY=@lists.php.net X-Gm-Message-State: AOJu0Yz+HDvYeyPsWd0ij1AFwkDe8kPSybdJPZsmNsLM4ao/EyMwcbN5 bhOjwAUHvVU7gD3bWo6i5jBJZoVj9f2GAG2omJbSLwrZTUAwp6gSZwx+Sv4VM1F2ZpsznKOXk89 SgY9DsqUkCN9aaqXTMRFXOrsj7+o= X-Gm-Gg: ASbGnct25cDONIwQmUruOD/UDU0cc1L3mNdJigiv1JyduvzJ4SZI70EKrlcHO/gk3+l PNsM1F6zaLQjUtp0YH4qRxf+J8YKy+CXJ8CZtV6cc4wkSiRXPubOren2fCqyMhY07lswem3EPUc qV2CYP3yyBKUvLc40/uIcf9S1fmBQt3S2Y16oz X-Google-Smtp-Source: AGHT+IGQ+BzAer7bCj61XKXrb11YamT0HfXAv60IlV88H6xNPP/YxqZ7dzzbmPS6d5YUC682J/HMB8nTnALo5fRFi18= X-Received: by 2002:a05:690c:d89:b0:6fd:385d:5f10 with SMTP id 00721157ae682-700bad0459dmr134601717b3.35.1742728904180; Sun, 23 Mar 2025 04:21:44 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <250fd68437fe3025e3aad9eff271dde3@bastelstu.be> In-Reply-To: Date: Sun, 23 Mar 2025 13:21:27 +0200 X-Gm-Features: AQ5f1JoQX2lHiMZ0Jligz1qfR7ShFyrXwARkr6g4YeEpcDiy8E39yW5k-TvvOqg Message-ID: Subject: Re: [PHP-DEV] Re: Constructor property promotion for final properties To: Daniel Scherzer Cc: =?UTF-8?Q?Tim_D=C3=BCsterhus?= , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000460cb9063100b11d" From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000460cb9063100b11d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 21, 2025 at 9:30=E2=80=AFPM Daniel Scherzer wrote: > > On Fri, Mar 21, 2025 at 9:45=E2=80=AFAM Alexandru P=C4=83tr=C4=83nescu > wrote: > >> >> On Fri, Mar 21, 2025 at 5:20=E2=80=AFPM Daniel Scherzer < >> daniel.e.scherzer@gmail.com> wrote: >> >>> On Fri, Mar 21, 2025 at 4:07=E2=80=AFAM Tim D=C3=BCsterhus wrote: >>> >>>> Can you clarify if the following would result in constructor property >>>> promotion or not: >>>> >>>> class Foo { >>>> public function __construct( >>>> final string $bar, >>>> ) { } >>>> } >>>> >>>> Best regards >>>> Tim D=C3=BCsterhus >>>> >>> >>> Yes, that would result in constructor property promotion. I'll need to >>> retarget the original PR for master, but at >>> https://github.com/php/php-src/pull/17861 you can see in >>> `Zend/tests/property_hooks/final_prop_promoted_2.phpt` a very similar t= est >>> case. >>> >>> >> I see. Good catch Tim. >> Daniel, you don't have this exact test case there. >> >> Initially, in 8.0, only a visibility keyword would trigger the property >> promotion logic. >> Later, in 8.1, also the readonly keyword would trigger this and make the >> property public, without the need to mention the visibility: >> https://3v4l.org/Co0gl >> >> Now we want the same for the final keyword, to trigger the property >> promotion without having a visibility keyword, >> because like readonly, it would not be applicable to a parameter, but >> just to a property? >> >> -- >> Alex >> > > Sorry, I completely missed that part. Yes, that should trigger promotion, > and if it doesn't then that is a bug in my implementation. When I retarge= t > the PR to master I'll also add a test case for promotion from just using > `final`. > > Hi Daniel, When discussing the Aviz RFC, I also wrote on this topic. ( https://news-web.php.net/php.internals/123488) The main issue being that if we ever decide to use the final modifier for a parameter, it would not be possible. It is already now possible to use the readonly modifier for a parameter because of this, something I wasn't aware of until this topic. On the readonly doing the promotion by itself, I believe it was an internal decision (that we properly documented later), but it was not discussed on the mailing list as far as I know. Also, I believe there might not be an actual test that validates this behavior. Having said that, allowing final to trigger property promotion by itself is not such a problematic thing, IMO. I would have preferred forcing a visibility keyword to trigger property promotions, but the cat is out of the bag already. Also, allowing the final modifier for constructor parameters to be transformed as the final modifier for promoted properties is fine. I guess that if we ever decide to use a keyword for declared variables or parameters to disallow changing their values, we can go with some other keyword like const, val, etc. --=20 Alex --000000000000460cb9063100b11d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, Mar 21,= 2025 at 9:30=E2=80=AFPM Daniel Scherzer <daniel.e.scherzer@gmail.com> wrote:

On Fri, Mar 21, 2025 at 9:45=E2=80=AFAM Alexandru P=C4=83tr=C4=83nescu &= lt;drealecs@gmail.c= om> wrote:

On Fri, Mar 21, 2025 at 5:20=E2=80=AFPM= Daniel Scherzer <daniel.e.scherzer@gmail.com> wrote:
On= Fri, Mar 21, 2025 at 4:07=E2=80=AFAM Tim D=C3=BCsterhus <tim@bastelstu.be> wrote:
Can you clarify if the following would result in constructor property <= br> promotion or not:

=C2=A0 =C2=A0 =C2=A0class Foo {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0public function __construct(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0final string $bar,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0) { }
=C2=A0 =C2=A0 =C2=A0}

Best regards
Tim D=C3=BCsterhus

Yes, that would resu= lt in constructor property promotion. I'll need to retarget the origina= l PR for master, but at=C2=A0https://github.com/php/php-src/pull/17861 you= can see in `Zend/tests/property_hooks/final_prop_promoted_2.phpt` a very s= imilar test case.


I see. Good catch Tim.
Daniel, you don't have this ex= act test case there.

Initially, in 8.0, only a vis= ibility keyword would trigger the property promotion logic.
Later= , in=C2=A08.1, also the readonly keyword would trigger this and make the pr= operty public, without the need to mention the visibility:=C2=A0https://3v4l.org/Co0gl
<= div>
Now we want the same for the final keyword, to trigger t= he property promotion without having a visibility keyword,
becaus= e=C2=A0like readonly, it would not be applicable=C2=A0to a parameter, but j= ust to a property?

--=C2=A0
Alex

Sorry, I completely missed that = part. Yes, that should trigger promotion, and if it doesn't then that i= s a bug in my implementation. When I retarget the PR to master I'll als= o add a test case for promotion from just using `final`.


Hi Daniel,
<= div>
When discussing the Aviz RFC, I also wrote on this topic= . (https://news-w= eb.php.net/php.internals/123488)
The main issue being that if= we ever decide to use the final modifier for a parameter, it would not be = possible.
It is already now possible to use the readonly modifier= for a parameter because of this, something I wasn't aware of until thi= s topic.

On the readonly doing the promotion by it= self, I believe it was an internal decision (that we properly documented la= ter), but it was not discussed on the mailing list as far as I know.
<= div>Also, I believe there might not be an actual test that validates this b= ehavior.

Having said that, allowing final to trigg= er property promotion by itself is not such a problematic thing,=C2=A0IMO. = I would have preferred=C2=A0forcing a visibility=C2=A0keyword to trigger pr= operty promotions, but the cat is out of the bag already.
Also, a= llowing the final modifier for constructor parameters to be transformed as = the final modifier for promoted properties is fine.

I guess that if we ever decide to use a keyword for declared variables or= parameters to disallow changing their values, we can go with some other ke= yword like const, val, etc.

--=C2=A0
Ale= x

--000000000000460cb9063100b11d--