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

Reply via email to