Re: [RFC] Guard statement

From: Date: Sat, 16 May 2020 12:52:35 +0000
Subject: Re: [RFC] Guard statement
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-110178@lists.php.net to get a copy of this message
Hi Pavel > https://wiki.php.net/rfc/guard_statement > <https://wiki.php.net/rfc/unbundle_xmlprc> First of all, thanks for your proposal! I'm a bit skeptical. guard is mostly useful in Swift because it's a strictly typed language. let x = foo() // type Int? if x == nil { return } // x is still Int? Guard is kind of an inverted if statement for them. guard let x = foo() { return } // x is Int In PHP we don't have this problem as there are no (or few) compile time type checks. guard (null !== $x = foo()) { return; } // No benefit over if (null !== $x = foo()) { return; } The only benefit is that the block is forced to be terminating but that's not worth it IMO. Ilija

« previous php.internals (#110178) next »