Re: [RFC] switch expression

From: Date: Wed, 25 Mar 2020 18:24:41 +0000
Subject: Re: [RFC] switch expression
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-109306@lists.php.net to get a copy of this message
Hi, internals, ---- En mié, 25 mar 2020 17:21:29 +0100 Rowan Tommins <rowan.collins@gmail.com> escribió ---- > On Wed, 25 Mar 2020 at 15:29, Ilija Tovilo <ilija.tovilo@me.com> wrote: > > > I don't think this would add any significant benefit over: > > > > ```php > > $x = true switch { > > $x !== null && $x < 5 => ... > > } > > ``` > > > > > The problem with that is that it requires a temporary variable to be > switched on. If I want to switch on, say, a method call, I can write this > for equality: > > $result = $this->foo($bar) switch { > 1 => 'hello', > 2 => 'hi', > 3 => 'goodbye' > }; In this case, you can also do: $result = [ 1 => 'hello', 2 => 'hi', 3 => 'goodbye' ][$this->foo($bar)]; With syntax very similar to proposed switch but this is using array. Regards -- Manuel Canga

« previous php.internals (#109306) next »