Re: Proposal for PHP 7 : case-sensitive symbols
| From: | Andrea Faulds | Date: | Sat, 20 Dec 2014 22:45:39 +0000 |
| Subject: | Re: Proposal for PHP 7 : case-sensitive symbols | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79827@lists.php.net to get a copy of this message | ||
Hey François, (I assume there’s a ç, I apologise if not)
> On 20 Dec 2014, at 22:01, F & N Laupretre <nf.laupretre@yahoo.fr> wrote:
>
> I don't know if this was discussed before. So, tell me what you think before
> I write an RFC.
Ah, this subject has come up before, I think. :)
> I would like to propose that namespaces, functions, and classes become
> case-sensitive (constants are already case-sensitive). Actually, I never
> understood why they are case-insensitive. Even if the performance gain is
> negligible, I think it could be the right time to question this.
I’d thought of doing this before, but the backwards-compatibility cost is too high.
I would like to see more case uniformity, but I think this is the less practical direction. Instead
of making everything case-sensitive, we should make everything case-insensitive, which would break
far less stuff, and is a smaller change. That’d mean constants, variable names and properties
would need changing, everything else is already case-insensitive.
I don’t think making constants and variable names case-insensitive would cause a problem. I reckon
it’s unlikely that someone has two constants differing only by case, ditto for variable names, and
both live in their own namespaces so this wouldn’t create conflicts. Even if someone does, this is
probably quite a rare occurrence and could be easily fixed.
The problematic case is properties, because although PHP code probably doesn’t rely on them being
case-sensitive most of the time, lacking preservation of case for serialised properties would be
quite a problem. For example, an object serialised to JSON and then decoded might, with the right
flags passed, be unserialised as an array. Array keys are case-sensitive in PHP (as they should be,
I don’t want to change that), so now a lookup that worked before might not now because the case
wasn’t preserved. Even if we took care to preserve case, there’s also the problem of objects
used as associative arrays, which we explicitly encourage with ArrayObject. Plus, JSON objects
decode to PHP objects by default, so objects used as case-sensitive dictionaries in incoming JSON
would break. For these reasons, I don’t think we should touch properties.
In summary, case-sensitivity everywhere would be a massive BC break, but case-insensitivity for
everything except properties might be doable.
Thanks for writing! :)
--
Andrea Faulds
http://ajf.me/