Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126276 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 482FA1A00BC for ; Mon, 3 Feb 2025 19:08:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738609538; bh=Q82DkBYI0IBg0MebtMrRey9/TWbWu5jAPUM1NuZ+stw=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=Zancr28h0D/okRm8vaN8Y2+6v47muQZuAjMEb97xFPbGkEfrBsXb0kwkFCoLHDtFb D0h+f7FHwi0Ob1piX1WteHVtpJDkjrrYwp9B9dUyj3MLtzJ8uCtBQ5rN7qy8VIRoAR p/2dRT8xcYo/SyGFx+3JGxiuFXoRqHmUzhIXdkKi7Fbuk9wOODxC2O5RqDaObWN93K FaVLJ6ZDR02ezaJpMMLmNfrNiY8qquEhABZWGpdbsWjEXMQGSU+ldZ3vPy6g1o4IkG 1rUPvDj8OVr7zjQ8TQus9iw4jehV5hEQjb8V1AUJGbgbyCrVCwdeS6fJKuXhgz8xqY pbAXqGSPPz7kg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D82081801D4 for ; Mon, 3 Feb 2025 19:05:37 +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.9 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (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 ; Mon, 3 Feb 2025 19:05:37 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 49C8F25401A8; Mon, 3 Feb 2025 14:08:23 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Mon, 03 Feb 2025 14:08:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1738609703; x= 1738696103; bh=Q82DkBYI0IBg0MebtMrRey9/TWbWu5jAPUM1NuZ+stw=; b=P rfqk2nOmXsnbwf7DpUvip78Uc62IX6eo+o4aw3CYA4nmVu4FbRKO3zWnBJt00zw9 Nt6xJFb5aYSjQoieYrs7fGNMMcXZTr8/HQxM5nTlnFqvNHeRBKkBJJ1C1APTIpBJ f8fr8ewQBPCKFr8HxGjYUTwWIymJGZ8GAiIvZ113gK/guoh/19g6DPnjh2+OqdfY Pv3vlRGA51xbtfW24T4LPkdFjXVwEf955DdE37bNvy1KnNqHmeMnBileMPKXe9Bz QXOIOIPsJggaAXXGaLs3ynKm6INY2UOdCLt+yVqEaBn5aupcOaszq9c3lbNrStzq WUygBuUfgh4XN/Fi2IM5g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1738609703; x=1738696103; bh=Q82DkBYI0IBg0MebtMrRey9/TWbWu5jAPUM 1NuZ+stw=; b=NmZjnfAAi/HHbISDl302vb/pdgwIyyDmj7YZmV2Wsu2HaE1aFR0 8O3jWUA0KGnMBlRF1snNQC6BUE1jMLnc1yWNkOXATo06MIE2XJ0FDo/QxbYgdisI U1dg2P40o9Vt4Kty7VK/ymj9WMP8Ws1xm4F8HU+jsrnAtqg2+v5juiZtret8bRDP AbNEnWZzPPtTufZGGq66+9kB7HzRH8PLMBaoarLQEuvxsUzWY7wXDfBSvxNJ+nVu EuuW21PvEU+ewihArL5GXZfd/9PV8nKlrU6j+19UuMr6MVcWIA0htvs5eLrYyj6H aP4sL9H2WA+Yai1i1grSEYZClANQaiqgJrg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddukeegtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggff fhvfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhs fdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpefgff euieevfeefgfekffevjeefheetveeitefhgfehfeehgefgveekjefhfeekteenucffohhm rghinhepghhithhhuhgsrdgtohhmpdhphhhprdhnvghtnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggv shdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplh grnhguvghrshdrrhhosggvrhhtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepgigvphho iiiiugesghhmrghilhdrtghomhdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsth hsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id DA7F7780068; Mon, 3 Feb 2025 14:08:22 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 03 Feb 2025 20:08:02 +0100 To: "Dmitry Derepko" , "Rob Landers" Cc: internals Message-ID: In-Reply-To: <883cfc0a-cf18-4470-a21a-ca8470f090de@app.fastmail.com> References: <878EED34-B28D-48FE-8EBE-5929841C12BD@gmail.com> <883cfc0a-cf18-4470-a21a-ca8470f090de@app.fastmail.com> Subject: Re: [PHP-DEV] Re: Discussion: making continue and break into an expression Content-Type: multipart/alternative; boundary=cb9756668d1743038cf91f4a544c5bc8 From: rob@bottled.codes ("Rob Landers") --cb9756668d1743038cf91f4a544c5bc8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Feb 3, 2025, at 19:44, Rob Landers wrote: > On Sun, Feb 2, 2025, at 14:35, Dmitry Derepko wrote: >>=20 >>> On Jan 25, 2024, at 12:16=E2=80=AFPM, Robert Landers wrote: >>>=20 >>> Hello internals, >>>=20 >>> Now that throwing is an expression, it allows for some very concise >>> programming. What are your thoughts on making a break/continue into = an >>> expression as well? >>=20 >> Hi!=20 >> I had similar idea to make `break`, `continue` and `return` be expres= sions instead of statements to simplify almost the same cases as Robert = described above. >>=20 >> Grammar corrections in the PR. https://github.com/php/php-src/pull/17= 647=20 >> Ilija pointed to memory leaking problems as well. >>=20 >> Thinking about Ilija memory leaking case: >> new Foo + return 1 >>=20 >> I think we may have a workaround here, by allowing all of these const= ructions only available at some specific points: >> - as the statement now >> - $cond ? : ; >> - match ($v) { =E2=80=A6 =3D> } >>=20 >> So it will deny such cases: >> - operand OPERATOR (1 + return; $cond && break; etc) >>=20 >> It may prevent memory leaking problems. Isn=E2=80=99t it? >>=20 >> I=E2=80=99m writing RFC: https://wiki.php.net/rfc/return_break_contin= ue_expressions=20 >> I=E2=80=99ll start a new discussion when it will be ready for it. >>=20 >>=20 >> ---------- >>=20 >> Best regards, >> Dmitrii Derepko. >> @xepozz >=20 > Oh, this was a fun one! >=20 > I ended up rewriting the AST during compilation (pass 2) to return/bre= ak on the next statement instead of in the current statement. That let m= e get around the issue but I guessed nobody would like it and it probabl= y wouldn=E2=80=99t pass on technical reasons. >=20 > In other words, yes it was an expression on the grammar level, but it = was compiled as a statement. >=20 > =E2=80=94 Rob Hello again, I just finished reviewing the diff and didn't notice any tests that show= what the value of things actually become. In my diff, I did something l= ike this: $this->x =3D return $y; // $this->x =3D=3D=3D $y Which is basically shorthand for: $this->x =3D $y; return $y; An empty return, break, or continue (well, only one of these has a value= ) contains the value NULL: $this->x =3D break; // $this->x =3D=3D=3D null Shorthand for: $thix->x =3D null; break; I'm trying to figure out which branch this was on ... but it was likely = on my old computer since I originally sent it the email from my gmail ad= dress. =E2=80=94 Rob --cb9756668d1743038cf91f4a544c5bc8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Mon, Feb = 3, 2025, at 19:44, Rob Landers wrote:
On Sun, Feb 2, 2025, at 14:35, Dmitry Derepko= wrote:

On Jan 25, 2024, at 12:16=E2=80=AFPM, Robert Landers <= landers.robert@gmail.com> wrote:

Hello internals,

Now that throwing is an= expression, it allows for some very concise
programming. = What are your thoughts on making a break/continue into an
= expression as well?

Hi! 
I had similar idea to make `break`,= `continue` and `return` be expressions instead of statements to simplif= y almost the same cases as Robert described above.

Grammar corrections in the PR. https://github.com/php/php-src/pull/17647&= nbsp;
Ilija pointed to memory leaking problems as well.

Thinking about Ilija memory leaking case:
=
new Foo + return 1

I think we ma= y have a workaround here, by allowing all of these constructions only av= ailable at some specific points:
- <point> as the st= atement now
- $cond ? <point> : <point>;
- match ($v) { =E2=80=A6 =3D> <point> }
=
So it will deny such cases:
- operand OPERA= TOR <point> (1 + return; $cond && break; etc)

It may prevent memory leaking problems. Isn=E2=80=99t i= t?

= I=E2=80=99ll start a new discussion when it will be ready for it.


----------

Best regards,
Dmitrii Derepko.
@xepozz

Oh, this was a fun one!

I e= nded up rewriting the AST during compilation (pass 2) to return/break on= the next statement instead of in the current statement. That let me get= around the issue but I guessed nobody would like it and it probably wou= ldn=E2=80=99t pass on technical reasons.

In= other words, yes it was an expression on the grammar level, but it was = compiled as a statement.

=E2=80=94 Rob

Hello again= ,

I just finished reviewing the diff and di= dn't notice any tests that show what the value of things actually become= . In my diff, I did something like this:

$t= his->x =3D return $y; // $this->x =3D=3D=3D $y

<= /div>
Which is basically shorthand for:

$this->x =3D $y;
return $y;

An empty return, break, or continue (well, only one of these has a va= lue) contains the value NULL:

$this->x =3D= break; // $this->x =3D=3D=3D null

Short= hand for:

$thix->x =3D null;
break;

I'm trying to figure out which br= anch this was on ... but it was likely on my old computer since I origin= ally sent it the email from my gmail address.

=E2=80=94 Rob
--cb9756668d1743038cf91f4a544c5bc8--