Re: Discussion: making continue and break into an expression
| From: | Dmitry Derepko | Date: | Sun, 02 Feb 2025 13:35:33 +0000 |
| Subject: | Re: Discussion: making continue and break into an expression | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126269@lists.php.net to get a copy of this message | ||
> On Jan 25, 2024, at 12:16 PM, 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 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?
I’m writing RFC: https://wiki.php.net/rfc/return_break_continue_expressions
I’ll start a new discussion when it will be ready for it.
----------
Best regards,
Dmitrii Derepko.
@xepozz