First impressions about namespaces in PHP


I’ve been working wih my first project using namenspaces in PHP. As a PHP developer I have been suffering the lack of a program language without namespaces for years. But now it’s over. Finally we have namespaces in PHP since PHP 5.3. My early impressions wasn’t good. I had a problem. I really liked PEAR naming conventions. I know that leads to those ugly long class names, but I felt very comfortable with them. I even started to write a post in my blog called “Things I don’t like in PHP. Namespaces”. But I decided not to publish it since have been working a bit seriously with them. Now I have use them and my impressions have been changed. I’ve embraced them and they are not so bad. They have the same advantages than PEAR naming conventions and they give us some extra benefits further. Here we have a great article about namenspaces in PHP5.3

The only doubt I have is: Are they really better than classical naming conventions?
I make myself the question because as well as in classical naming convention the Classes are fully defined, with namespaces we must take care about aliases, ‘use’ statements and the scope. When I say ‘fully defined’ it means that in a glance to the class name we known exactly the location of the class in the filesystem.. We pay a tax for it. Our class name become bigger. Namespaces come to help us but they add to our code a bit of complexity. I feel really comfortable with classical naming conventions but namespaces are cool. Are they some kind of hype? I don’t think so but I am not 100% convinced. Yet. What do you think?

Advertisement

4 thoughts on “First impressions about namespaces in PHP

  1. I have a framework which I aim to modify to make use of the new namespace support in PHP 5.3.x, but whenever I look into doing this the ugly syntax (yes the backslash!) really puts me off engaging with namespaces in PHP.

    1. I’m afraid you’re not the only one :). But after a few days working on it it’s not so bad. Even, I feel it’s useful. This symbol is so ugly for me that I can easily detect any reference to namespaces within the code in a glance. And that’s cool. isn’t it?. (maybe it’s my way to convince myself because it’s really ugly)

  2. The addition of the namespaces was the kick in the butt I needed to start using python. The guys hacking this language just don’t give a damn.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.