Re: Adding explicit intent for SWITCH/CASE fall through?

From: Date: Sun, 20 Oct 2019 21:44:48 +0000
Subject: Re: Adding explicit intent for SWITCH/CASE fall through?
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-107594@lists.php.net to get a copy of this message
> On Oct 20, 2019, at 7:28 AM, Rowan Tommins <rowan.collins@gmail.com> wrote: > On 20/10/2019 01:39, Mike Schinkel wrote: >> Not yet having experience working on PHP's parser I do not know how it is configured >> nor what about the design of PHP requires keywords unable to be used as constants, class names, >> function or method names. I know this is a tangent but that seems like a requirement designed to >> simplify the parser maybe, and not because of any logical requirement. So I assume whatever word was >> used for this would also have to be a reserved keyword? Or not? > > > I don't know the full implications in the parser, but at the language level, any constant > can technically appear where this keyword would. That is, the following is valid right now: > > const fallthrough=null; > fallthrough; > > It doesn't do anything, but it's valid because any expression on its own is a valid > statement, and a constant on its own is a valid expression. Thank you for clarifying that. Still, I wonder if a reserved word really needs to disallow function, method, class and trait names, which are more problematic to me. I have often wanted to name a class 'List. And I have often wanted to name a method do(), continue(), end() and try()`. Seems like a needless limitation thus forcing the use of less appropriate symbol naming. > Interestingly, that actually makes a single keyword *more* appealing to me, because it means > you can get *forwards* compatibility by writing this: > > if ( PHP_VERSION < 80000 && ! defined('fallthrough') ) { > define('fallthrough', null); > } Oh, that is interesting! Too bad you can't define a constant to call an initializer method. -Mike

« previous php.internals (#107594) next »