On Mon, 21 Oct 2019 at 15:13, Mike Schinkel <m...@newclarity.net> wrote:
> Ok, so let's look at a scenario. Will we be able to do this in the future, > if we decide to allow multiple expressions to result in a final value? > $y = switch ($x) { > case 1 => $arr = get_array(), array_pop($arr), > case -1 => $arr = get_array(), array_unshift($arr), > default => null, > }; > Unlike some languages, not every statement in PHP is a valid expression (e.g. you cannot write "$foo = echo $bar"), so regardless of whether we use commas or semi-colons, the right-hand-side in those examples would have to be some new construct, so we could choose whatever syntax we wanted for it. We'd probably want something other than bare commas anyway, to make it more widely usable, e.g. in array declarations. If what you want is a full *statement* block on the right hand side, then you'll need to use the current switch statement anyway. > What if in the future PHP implements variadic syntax for assigning to > arrays, e.g. $var = 1,2,3 where $var could satisfy a $variadic parameter > set of parameters w/o requiring `...`? If PHP embraces that — note GoLang > has something similar — then will comma syntax allow for it with hacky use > of parentheses? > $y = switch ($x) { > case 1 => $var = 1,2,3, $var[1], > case -1 => $var = 9,8,7, $var[1], > default => null, > }; I'm not really clear what feature you're suggesting here, but I'm pretty sure it conflicts with existing uses of commas, so shouldn't constrain us from using them elsewhere. foo(1,2,3); foo($var = 1,2,3); $a = [0, $var = 1,2,3]; // etc Regards, -- Rowan Tommins [IMSoP]