Re: Proposal For Return-If / Early Return / Guard Clause Syntax

From: Date: Wed, 13 May 2020 09:42:17 +0000
Subject: Re: Proposal For Return-If / Early Return / Guard Clause Syntax
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-110149@lists.php.net to get a copy of this message
Le Sun, 10 May 2020 10:49:15 -0500, Ralph Schindler <ralph@ralphschindler.com> a écrit : > The chosen syntax is: > > return if ( if_expr ) [: optional_return_expression] ; > > As a contrived example: > > function divide($dividend, $divisor = null) { > return if ($divisor === null || $divisor === 0); > > return $dividend / $divisor; > } I do not understand the point, you are just reordering keywords, why is that better than already correct code: function divide($dividend, $divisor = null) { if ($divisor === null || $divisor === 0) return; return $dividend / $divisor; } I do not think an RFC and a special keyword are justified just to move the word "return" from end to beginning of line.

« previous php.internals (#110149) next »