Re: Re: Discussion: making continue and break into an expression
| From: | Ilija Tovilo | Date: | Sun, 02 Feb 2025 20:56:54 +0000 |
| Subject: | Re: Re: Discussion: making continue and break into an expression | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126273@lists.php.net to get a copy of this message | ||
Hi Dmitrii
On Sun, Feb 2, 2025 at 2:36 PM Dmitry Derepko <xepozzd@gmail.com> wrote:
>
> I had similar idea to make
break,
> continue and return be expressions
> instead of statements to simplify almost the same cases as Robert described above.
>
> Grammar corrections in the PR.
> https://github.com/php/php-src/pull/17647
> Ilija pointed to memory leaking problems as well.
>
> Thinking about Ilija memory leaking case:
> new Foo + return 1
>
> I think we may have a workaround here, by allowing all of these constructions only available at
> some specific points:
> - <point> as the statement now
> - $cond ? <point> : <point>;
> - match ($v) { … => <point> }
>
> So it will deny such cases:
> - operand OPERATOR <point> (1 + return; $cond && break; etc)
>
> It may prevent memory leaking problems. Isn’t it?
Note that technical discussions don't need to happen on the internals
mailing list. It has a lot of recipients and they are usually not
interesting to the majority of people. GH is a better place for that.
This alone will not be sufficient, because the ?: and match
expressions themselves may be nested in other expressions that create
temporary variables. E.g. new Foo + ($cond ? $x : break) will create
the same issue. Restricting control flow statements fully to a
combination of these expressions would work, however is also less
useful and thus less persuasive. In my experience, incomprehensible
limitations are generally not well received by internals.
Ilija