PHP Namespace Delimiter Controversy: “set sail for fail”
PHP is a popular, and often maligned scripting language, which evolved originally as a means for creating dynamic web pages. The software that runs the iSchool website, “Drupal,” is written in PHP. One of the biggest criticisms with PHP is the fact that it has thousands of built in functions, many of which share the same “namespace.” If you recall from our XML lectures, a namespace allows one to use the same element names from different XML vocabularies in the same document, as long as they are referenced in the context of their namespace. For example, two elements with the ID “name” can be used in the same XML document, if each has a unique namespace:
<book:name>Some Book Title</book:name>
<store:name>Some Store Title</store:name>
Some PHP function names get around this problem by having long psudeo-namespace identifiers, such as “preg_match_all” (performs a global reg/ex match). Unfortunately, there is not a lot of standardization between these names, meaning coders must deal with time-consuming inconsistencies. PHP developers recently decided that real namespaces are an important feature, but were not in agreement as to how to implement them. XML, as you know, uses the colon, “:”, to facilitate namespaces within a tag . Other languages, like Python and Java, use a dot, “.”, to define which classes are imported from a particular package’s namespace. However, PHP developers have decided to define a namespace using the backslash, “\”, which has generated quite a bit of criticism. One major concern is that the backslash is also used as an escape code for special characters, such as “Tab” – which can also be represented as “\t.” So, will there be cases in the PHP code where a function like “MyPackage\transform” will be misread as “MyPackage[TAB]ransform?” Also, backslash is not in the same place on different keyboard layouts. Is this a choice that is biased toward certain users? One blogger has referred to the backspace choice as a decision that will cause PHP to “set sail for fail.”
Like the standardization negotiations we discussed in class, the PHP namespace implementation came about after quite a lot of discussion. However, based on the controversy, discussion probably could have used a little more time, and a few more voices before a final decision was made. Today, Slashdot had a link to the long IRC chat log where the choice was finalized, and here is a link to the pros and cons of namespace design on php.net.