Hi Mike

I think your hypothetical PHP syntax won't happen. Not because it's bad
idea but because PHP just simply can't. I understand that you came up with
that idea from Golang background but the reason Golang can do that because
in Golang, assignments are statement not expression. Even `++` or `--` are
statement in Golang. While assignments in PHP are expressions so they can
appear in any expression contexts. And it will conflict with other places
as Rowan said in previous reply.

You could instead simply assume that case statements supports multiple
> lines with the last providing the value, and thus not requiring the use of
> an explicit `eval()`.
>

I'm not fond of implicit things. And I think my proposed solution is more
useful because it can return value anywhere not just at the end. You might
think it is complex or visually busy but others may feel it is more
comfortable if they are able to write well structured and and cleaner codes
by this way.

Regards

On Tue, Oct 22, 2019 at 3:42 AM Mike Schinkel <m...@newclarity.net> wrote:

> On Oct 20, 2019, at 11:11 PM, Kosit Supanyo <webdevxp....@gmail.com>
> 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,
> };
>
> As I told you in previous reply, I'm working on block-expressions as well.
> So if PHP has block-expressions you can do the same this way:
>
> $y = switch ($x) {
>     case 1 => eval {
>         $arr = get_array();
>         give array_pop($arr);
>     },
>     case -1 => eval {
>         $arr = get_array();
>         give array_shift($arr);
>     },
>     default => null,
> };
>
>
> I know you said you were working on block expressions, but I did not view
> that as the best solution to the question I asked although I see that is
> how you envision it.
>
>
>
> Which is obviously cleaner and more powerful.
>
>
> That is arguable. I find the solution you proposed above that uses
> `eval()` to be very "busy" visually, and needlessly complex/  You could
> instead simply assume that case statements supports multiple lines with the
> last providing the value, and thus not requiring the use of an explicit
> `eval()`. But to do that would require semi-colon line terminators, I think.
>
> Note I also think `eval()` would also be a nice to have, but what would be
> even nicer is if the inline switch did not require use of `eval()` to
> support multiple lines per case.
>
> #fwiw
>
> -Mike
>
>
>
>
>
>
>

Reply via email to