Re: [PHP-DEV] Proposal For Return-If / Early Return / Guard Clause Syntax

This is only part of a thread. view whole thread
  110161
May 15, 2020 08:33 benas.molis.iml@gmail.com (Benas IML)
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
  110167
May 15, 2020 13:36 jbafford@zort.net (John Bafford)
Benas,

> On May 15, 2020, at 04:33, Benas IML 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
  110168
May 15, 2020 13:57 benas.molis.iml@gmail.com (Benas IML)
Hello,

Not it's not and will likely never be so using `guard` is a really bad idea.

Best regaeds,
Benas Seliuginas