Re: Return When
| From: | Christoph M. Becker | Date: | Tue, 26 Nov 2024 17:16:01 +0000 |
| Subject: | Re: Return When | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126060@lists.php.net to get a copy of this message | ||
On 26.11.2024 at 17:10, Volodymyr Volynets wrote:
> I have an idea which will save a lot of code. I am proposing to add":
>
> return when [condition], [return value];
>
> This construct will remove a lot of ifs statements after method calls. For
> example:
>
> $result = Class->method();
> if (!$result['success']) {
> return $result;
> }
>
> This becomes:
> return when !$result['success'], $result;
>
> Any thoughts?
What's wrong with
if (!$result['success']) return $result;
That's not longer than what you are proposing, and in my opinion, quite
readable.
The fact that contemporary coding standards require you to write the
if-body on a separate line and to always use braces, is perhaps a
problem of these coding standards.
Christoph