Re: Inline switch as alternative to nested inline conditional

From: Date: Thu, 17 Oct 2019 09:05:48 +0000
Subject: Re: Inline switch as alternative to nested inline conditional
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-107566@lists.php.net to get a copy of this message
On Wed, 16 Oct 2019 at 18:10, Bob Weinand <bobwei9@hotmail.com> wrote: > what's the concrete advantage of this syntax as opposed to the already > possible: > > $value = [ > A1 => A2, > B1 => B2, > ][expr()] ?? C; > What's the concrete advantage of switch over if-elseif? What's the concrete advantage of if blocks over conditional jumps? The primary answer in all three cases is surely "expressiveness". If I came upon code like that, it would take me a while to understand its intent - does $value end up as an array, or something else? what's the ?? there for, and when will expression C be used? Now, it may be that the task in question isn't common enough to deserve its own syntax, or you may not like the proposed syntax, but I think that's very different from coming up with lots of clever ways of writing something, and requiring new syntax to have a "concrete advantage" over each one. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#107566) next »