Skip to content

Instantly share code, notes, and snippets.

@nathggns
Created January 7, 2013 04:35
Show Gist options
  • Select an option

  • Save nathggns/4472349 to your computer and use it in GitHub Desktop.

Select an option

Save nathggns/4472349 to your computer and use it in GitHub Desktop.
What's so bad about PHP namespacing?

What's bad about Namespacing?

Nearly everything about PHP namespacing is absolutely terrible.

Standard Library

If you use PHP namespacing and you want to use a class from the standard library, you have to use a fully qualified class name.

<?php

namespace Scaffold;

class ExceptionRouting extends \Exception {}

That makes it horrific to implement namespacing in an existing project.

Non-Uniform

Also, quite a bit of PHP doesn't allow for relatively-qualified class names.

For example, say you have the namespace Scaffold, and a class Service inside of it. Outside of the Scaffold namespace, you have to refer to this class as Scaffold\Service, this is called a fully qualified class name. However, inside, you can just refer to it as Service, this is called a relatively qualified class name. However, call_user_func and many other PHP functions don't allow for relatively qualified class names. It's far too archaic.

Dynamic Importing

It's impossible to dynamically import a class name into your namespace. This is horrible, as you have to fully qualify your class names if you want to import them on-condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment