Re: Inline switch as alternative to nested inline conditional

From: Date: Wed, 16 Oct 2019 22:32:19 +0000
Subject: Re: Inline switch as alternative to nested inline conditional
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-107564@lists.php.net to get a copy of this message
> On Oct 16, 2019, at 5:21 PM, 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; Speaking specifically to your example, it does not handle multiple cases. IOW, you cannot do this: $value = [ A1 => A2, B1,C1, D1 => BCD2, E1 => E2, ][expr()] ?? F; A lesser concern is it must allocate memory for the array simply to implement the switch. Given that I would almost always avoid using that approach because I assume it is always best not to allocate memory unless really needed. Even if allocating the memory is not a problem, I expect other developers might have aversion to that technique based on similar assumptions. -Mike P.S. I am not sold on the proposal as is; I plan a follow up later with my concerns.

« previous php.internals (#107564) next »