Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-18 Thread Mike Schinkel
> On Oct 15, 2019, at 11:33 PM, Michał Brzuchalski > wrote: > > I have an RFC in draft for that and planning to finish it soon together > with some syntax optimisations - you can see it at > https://wiki.php.net/rfc/switch-expression-and-statement-improvement > > Cheers, > Michał Brzuchalski

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-17 Thread Rowan Tommins
On Wed, 16 Oct 2019 at 18:10, Bob Weinand 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

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Mike Schinkel
> On Oct 16, 2019, at 5:21 PM, Bob Weinand 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:

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Bob Weinand
Am 16.10.2019 um 21:19 schrieb Claude Pache mailto:claude.pa...@gmail.com>>: Le 16 oct. 2019 à 19:11, Bob Weinand mailto:bobw...@hotmail.com>> a écrit : Am 16.10.2019 um 03:46 schrieb David Rodrigues mailto:david.pro...@gmail.com>>: Hello. I like to suggests a discussion about a FR to make

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Claude Pache
> Le 16 oct. 2019 à 19:11, Bob Weinand a écrit : > >  >> >> Am 16.10.2019 um 03:46 schrieb David Rodrigues : >> >> Hello. I like to suggests a discussion about a FR to make possible to >> inline switch, as an alternative to nested inline conditionals. >> >> $value = switch (expr()) { >>

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Bob Weinand
> Am 16.10.2019 um 03:46 schrieb David Rodrigues : > > Hello. I like to suggests a discussion about a FR to make possible to > inline switch, as an alternative to nested inline conditionals. > > $value = switch (expr()) { >case A1: return A2; >case B1: return B2; >default: return C;

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Kosit Supanyo
Hi Robert That is impossible to implement because there's no way to tell the parser that `switch` is statement or expression and it conflicts with `=>` in array key expression (that's why PHP chose to have arrow function with `fn` prefixed). And IMO your idea is harder to read than normal

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Rowan Tommins
On Wed, 16 Oct 2019 at 14:58, Robert Hickman wrote: > > > > > $say = switch (date("w")) { > > > case 0 => "weekend!"; > > > case 1, 2, 3, 4, 5 => "weekday :("; > > > case 6 => "weekend!"; > > > }; > > > echo "Today is {$say}"; > > If you had a really long expression, it may be

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Robert Hickman
> > > $say = switch (date("w")) { > > case 0 => "weekend!"; > > case 1, 2, 3, 4, 5 => "weekday :("; > > case 6 => "weekend!"; > > }; > > echo "Today is {$say}"; If you had a really long expression, it may be easier to read if the assignment was moved to the end, perhaps like this:

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Chase Peeler
On Wed, Oct 16, 2019 at 4:37 AM Kosit Supanyo wrote: > I mean separation between cases not case conditions. Examples in your RFC > uses semicolon as case separator instead of comma. > > $say = switch (date("w")) { > case 0 => "weekend!"; > case 1, 2, 3, 4, 5 => "weekday :("; > case

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Kosit Supanyo
I mean separation between cases not case conditions. Examples in your RFC uses semicolon as case separator instead of comma. "weekend!"; case 1, 2, 3, 4, 5 => "weekday :("; case 6 => "weekend!"; }; echo "Today is {$say}"; I prefer comma because semicolon should only be used to separate

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Michał Brzuchalski
Hi Kosit, śr., 16 paź 2019 o 09:41 Kosit Supanyo napisał(a): > Hi Michal > > I'had the idea similar to your RFC but instead of using `switch` keyword I > think introducing `when` keyword is better. (as I know a language that uses > this keyword is Kotlin) > > $result = when ($v) { > 'foo'

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-16 Thread Kosit Supanyo
Hi Michal I'had the idea similar to your RFC but instead of using `switch` keyword I think introducing `when` keyword is better. (as I know a language that uses this keyword is Kotlin) $result = when ($v) { 'foo' => 1, 'bar' => 2, 'x', 'y', 'z' => 3, default => null, }; Above

Re: [PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-15 Thread Michał Brzuchalski
Hi David, I'm interested in this feature this is called switch expression and is on my list of RFC to process after Object Initializer RFC. I have an RFC in draft for that and planning to finish it soon together with some syntax optimisations - you can see it at

[PHP-DEV] Inline switch as alternative to nested inline conditional

2019-10-15 Thread David Rodrigues
Hello. I like to suggests a discussion about a FR to make possible to inline switch, as an alternative to nested inline conditionals. $value = switch (expr()) { case A1: return A2; case B1: return B2; default: return C; } Instead of: $expr = expr(); $value = $expr == A1 ? A2 : (