On Tue, Apr 28, 2020 at 6:58 PM Larry Garfield <la...@garfieldtech.com> wrote:
>
> On Tue, Apr 28, 2020, at 7:37 PM, Levi Morrison via internals wrote:
> > > One issue that was discussed a few weeks ago, and led to the current 
> > > syntax, was too many variations within the switch syntax; of course, 
> > > trying to do it all in one syntax is perpetuating that problem.  However, 
> > > I think Rowan has suggested a syntax that may be sufficiently 
> > > self-documenting.  To wit, independent of rustmatch (above):
> > >
> > > switch ($foo) {
> > >   case 1: {
> > >     Many statements here.
> > >   }
> > >   case 2: {
> > >     Many statements here.
> > >   }
> > > }
> > >
> > > The curly braces are already understood by most PHPers to mean "a block 
> > > of statements", and so it's a logical jump in this case.  As Rowan 
> > > suggests, the {} imply a break.  To keep it simple we should probably not 
> > > allow mixing and matching in a single switch.  Either list-style (break 
> > > required) or {}-style (break implied).
> > >
> > > That handles break;
> >
> > Sadly, it doesn't. That code is valid today:
> >
> >     <?php
> >     $foo = 1;
> >     switch ($foo) {
> >         case 1: {
> >             echo "1\n";
> >         }
> >         case 2: {
> >             echo "2\n";
> >         }
> >     }
> >     ?>
> >
> > Which outputs:
> > 1
> > 2
>
> ... Well, crap.  It just can't be easy, can it...
>
> Would it be too context-sensitive to have the {} version only work in strict 
> switch?
>
> Or for that matter... is anyone actually using that syntax in the wild, or is 
> it hypothetical?  Viz, if the behavior of that changed in 8.0 (a major 
> release), would that even break anything?  Even 7.4 has a couple of "the 
> behavior changed but seriously who was using this anyway?" points in it.  
> Could we get away with just changing it for 8.0?
>
> I'm not sure if Nikita's "check the top 1000" script could handle something 
> that subtle.
>
> --Larry Garfield
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php


I am confident it was used in a former employer's codebase, which is
how I immediately knew it was valid. My memory is too fuzzy to
remember anything more than it was used, unfortunately.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to