Is It Time to Ditch PHP?

PHP has long been a bread and butter language for me when it came to web-based projects. It’s what got me started in the whole web development business and essentially kick-started my whole career as a systems developer. But alas, recent developments in PHP land come as an unwelcome surprise. I’m talking about the much anticipated (for me anyway) namespace support. I have documented my basic gripes about PHP elsewhere. So I won’t go rambling about them again. I was excited to hear about namespaces finally getting implemented in PHP6 and backported to PHP5. But then when you read about bullshit like this you can’t help but wonder if the language’s direction has been taken over by a pack of neurotic, crack-smoking monkeys. Namespaces are a very important feature if one were to write large amounts of code without having to worry about symbol name clashes.

So, they want to replace the de facto standard namespace separator “::” with “\”. That’s right: replace double-colon with a backslash! Why? It’s because “::” is already being used in class method invocations and it will cause problems during parsing. Consider the following:

class Lol {
    public static function whut() {
    }

namespace Lol;

function whut() {
}

Elsewhere:

Lol::whut();

When you write Lol::whut(), which one are you talking about? Is it the static function in the class Lol? Or is it the function in the Lol namespace? I can think of a few solutions to this very simple problem besides changing the damned separator character.

  1. Throw an exception during parsing/compilation and complain that the symbol Lol has already been defined. Ideally it should say something sensible like: “Class name ‘Lol’ defined in main namespace conflicts with existing namespace definition ‘Lol’ found in FILE, line LINE.” For dynamically generated code, throw a runtime error and halt program execution. This is how C++ handles it, I can’t see why PHP can’t do the same. I would prefer it this way because I don’t want some moron programmer who is using my Lol library to write a class named Lol in the main namespace!

  2. Throw an exception like in #1 but make it a non-fatal exception and just let the class method defined in the main namespace take precedence. Or even let the function in the namespace take precendence. Do it one way over the other but tell the programmer that there is a problem with his code!

  3. Force Lol::whut() to resolve to the class method and ::Lol::whut() to resolve to the function defined in namespace Lol. Or vice versa.

I would really love to see arguments leveled against the 3 solutions above because changing the separator character is just plain stupid. Oh, and it’s butt ugly too. Sure it’s just in RFC but if this sort of stupid shit makes it into PHP6 then it’s time to say bye-bye PHP… It looks like they have their hearts set on using backslash as the namespace separator and it’s pretty much set in stone.

On a side note, when I was reading the RFC I had to take a second look at the date to make sure that it does not say April 1, 2008. They were considering the “smiley” as a namespace separator?!? Surely you jest!

Leave a Reply

Comments are moderated by the administrator. If this is your first time posting a comment, your comment will go to a moderation queue and it may take a while for your comment to appear. Or it may get deleted.