The road to PHP 5.3: Namespaces

We have all been looking forward to PHP6 and the big changes that were proposed for it, but along the way the PHP Core dudes made a great decision and split the PHP6 release in two. Most of the new features expected for PHP6 will be implemented in a 5.3 release, leaving unicode for the PHP6 release. So let’s take a quick look at what’s coming along in PHP 5.3.


On the last few weeks great steps have been taken, and a cool timeline is now up. The release went into feature freeze on the 24th of july, and into alpha1 last week. After that the next 2-3 weeks will see loads of beta and RC releases and finally from mid September to October we will have the final stable release \o/


On this post I’ll talk about Namespaces, and cover other features in future posts.


This is by far one of the most expected features that will be included in this release. Like Java or other languages, this will allow developers to group classes and other stuff in namespaces, like below:

/** classes/my/foo/MyClass.php */

namespace my::foo;

class MyClass {}

// You can define functions and constants in the namespace too.
function myFunc() { }
const MY_CONST = ‘foo’;


So that way you can use this in many forms, like:

/** test.php */

// You can always access anything ∈an object with fully qualified name.
$foo = new my::foo::MyClass();

// You can use the use statement to import a namespace.
use my::foo;
// After the above statement you can reffer for the my::foo namespace with foo.
$foo = new foo::MyClass();

// You can import only one class.
use my::foo::MyClass;
$foo = new MyClass;

// You can create aliases.
use my::foo as MyFoo;
use my::foo::MyClass as MyFooClass;
$foo = new MyFoo::MyClass();
$foo = new MyFooClass();

// Note, that the following two statements are equivalent:
use my::foo;
use my::foo as foo;

// You can access functions and constants in the same way:


You can also use “empty” namespaces, so using just (::), like ::MyClass, will ignore current rules and call a globally independent class.

You can read more details here:

Next up… Late Static Binding

2 thoughts on “The road to PHP 5.3: Namespaces

  1. How long till PHP 5.3 is out? I thought it was suposed to be out mid october 2008 but its now the end of November and its still in beta

  2. John

    Its been delayed, a month or so ago we had a real big discussion on the namespace separator, which ended up being “\” .. so this really affected the release dates and such.

    Check out the PHP Wiki for info.

Comments are closed.