Re: Deprecate alternate switch case syntax?

From: Date: Thu, 21 Nov 2024 11:54:16 +0000
Subject: Re: Deprecate alternate switch case syntax?
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-126023@lists.php.net to get a copy of this message
On 21.11.2024 at 10:36, Tim Düsterhus wrote: > This proposal would not affect that. You would just need to add a colon > after the case statement, not a semicolon. In fact that would > more > closely match the corresponding switch, which would also need > to have > a colon: > >     <?php $foo = "bar"; ?> > >     <?php >     switch ($foo): >     case "bar": >     ?> >     BAR >     <?php break; case "baz": ?> >     BAZ >     <?php endswitch; ?> > > Though using switch in such templates is somewhat finicky > anyway, > because it will need to be merged with the first case, because > otherwise: > >> Parse error: syntax error, unexpected T_INLINE_HTML "", expecting >> "endswitch" or "case" or "default" There is no parse error if you use PHP snippets in such templates like you use C preprocessor directives (i.e. always starting at the first column); e.g. https://3v4l.org/cK0Ll. Or see https://3v4l.org/7mKS8, which is how I would write it, if I was using switch statements in such templates. Note that I'm not advocating to keep the behavior, but I also don't see how it would be harmful. Without an enforced CS, there can be more confusing code anyway. Christoph

« previous php.internals (#126023) next »