doc:scratchpad:namespacefaq

Namespace FAQ

I think its mostly important we give answers of the type: [Yes,No], short reason (details at <url>):

Q: Couldn't these issues be solved by making PHP case sensitive?

A: No, this is not a viable solution, since PHP identifiers for the most part are case insensitive, changing this would essentially risk breaking compatibility with all PHP scripts in existence.

Q: Would removing constants/functions from namespaces make it possible to stick with “::” for namespaces?

A: Yes, but at a cost. Functions and constants within namespaced files would throw a fatal error. [Reference needed]

Q: Was the “::” separator was dropped because of limitations on the Zend Engine?

Q: Was the fact that the “\” character is harder to type on various international keyboards considered and if so why was this character still chosen?

A: Yes, it was considered. However the fact that “\” is already used in PHP means that nobody has a keyboard that actually lacks that character. There are also workarounds for those facing difficulties. [References needed]

Q: Why was character combination XYZ (“:::”, “@” etc.) not chosen?

A: There have been long and intensive public discussions over the choice of namespace separator in the past, and everyone at the internals meeting was familiar with the arguments against a wide range of potential characters. The possibilities were therefore very limited, as documented on the wiki page about this decision. [Link to Lukas' entry]

Q: Why was “\” chosen given that it makes it impossible to write something like “spl_autoload_register(array(“myNamespace\theLoader”, “load”));” because the \t would be interpreted as a tab?

A: It is already impossible to write Windows paths in PHP in the same way, ergo at least half the PHP community is already familiar with the idea that they need to either use single quotation marks or escape the backslash (“\\”).

Q: Why do the PHP internals developer think that “\” is not prone to cause issues when typos are made?

Q: Don't the PHP internals developer think that the fact that “\” is widely used as the escape character will be cause for confusion?

A: No, because the usage context is completely different.

Q: C++ uses “::” for namespaces, why did the PHP internals developers feel they needed to solve the ambiguity issues rather than leaving it to each developer to prevent ambiguity between namespace names and other identifiers?

A: Ambiguity is an edge case, meaning that developers wouldn't necessarily be aware of the potential for it through their own past experience, and debugging would be extremely difficult. Further, there was no way to provide a PHP error message on ambiguity without impacting performance in all cases. [Reference needed]

Q: Why wasn't the proposal chosen to just require “use namespace” and “use class” chosen?

Q: Do I have to prefix all my internal function names with \ now?

doc/scratchpad/namespacefaq.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1