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

From: Date: Fri, 15 May 2020 13:36:13 +0000
Subject: Re: Proposal For Return-If / Early Return / Guard Clause Syntax
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-110167@lists.php.net to get a copy of this message
Benas, > On May 15, 2020, at 04:33, Benas IML <benas.molis.iml@gmail.com> wrote: > > Hey, > > guard would be a keyword this means that all of the classes, > interfaces and traits named Guard would be illegal. Therefore Laravel's > Guard interface would be incompatible with PHP 8 which in turn means > thousands of web applications would be too. > > Best regards, > Benas Seliuginas If the parser were sufficiently smart, I don't think 'guard' would actually conflict with a class or function named 'guard'. If the syntax were: guard (EXPRESSION) else STATEMENT_OR_BLOCK then, 'guard' could not conflict with a class name, because there's no existing syntax that would fit the pattern of a type name followed by a parenthesis — you can't call a type name as if it were a function. Even if you could, it would still not conflict with a function call, because the 'else' keyword after the close parenthesis would not be valid syntax immediately following a function call. So the main question there is, is the parser sufficiently smart to be able to see 'guard' and look ahead for the 'else' to disambiguate a function call from a guard statement? -John

« previous php.internals (#110167) next »