Re: [RFC] Treat namespaced names as single token, relax reserved keyword restrictions

From: Date: Tue, 23 Jun 2020 17:45:18 +0000
Subject: Re: [RFC] Treat namespaced names as single token, relax reserved keyword restrictions
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-110710@lists.php.net to get a copy of this message
> Le 16 juin 2020 à 10:52, Nikita Popov <nikita.ppv@gmail.com> a écrit : > > Hi internals, > > Inspired by the recent discussion on reserved keyword reservation, I'd like > to propose the following RFC: > > https://wiki.php.net/rfc/namespaced_names_as_token > > This RFC makes two related changes: Treat namespaced names as a single > token, which enables use of reserved keywords inside them. And remove > reserved keyword restrictions from various declarations. > > The RFC comes with a small backwards compatibility break related to names > that include whitespace, but will hopefully reduce the backwards > compatibility impact of future reserved keyword additions. > > Regards, > Nikita In fact, for classes and namespaces, we can probably do better, namely we can lift almost all keyword restriction, not only in definition and declaration, but also in in use. Indeed, bare names of class (and trait, interface, etc) and namespace can appear only in few, well-defined positions, where it cannot be confused with a keyword, namely: * after a handful of keywords: new yield, class yield, instanceof yield, use yield, use foo as yield, etc. * before a paamayim nekudotayim: yield::$foo, yield::foo(), yield::FOO; * before a backslash: yield\foo. As far as I can see, the only keywords that can legally appear in those positions (and therefore must remain unavailable) are: namespace (because of namespace-relative names: namespace\foo), and class (because of anonymous classes: new class { }. (As for functions and constants, I’m still thinking that it is not a good idea to allow to define or import a symbol that cannot be used. You will make the life of few library maintainers a little easier, but you will make the life of many users a little harder.) —Claude

« previous php.internals (#110710) next »