Fun with namespacing

I’ve begun work on a namespace enabled version of my framework, primarily to separate project and framework code. I have the autoloader working but there are snags.

This is what I would love to be able to do - overriding. Say I have a page controller - Page. The authoritative copy is Framework\Page. In the project I would like to create a Project\Page class. If the autoloader encounters a request for “Page” I would like it to first look for Project\Page and if it doesn’t exist, load Framework\Page. However, if the namespace is specified I want to load the specific copy.

The power I seek is expressed in this code

namespace Project;

class Page extends \\Framework\\Page

So I can adjust the page class to the needs of the project at hand. But going further, Say I have a framework extending class of page

class SpecialPage extends Page

I want the autoloader to again include Project\Page in preference to going straight up the tree to Framework page.

I’m still groking namespaces, but this sort of stuff is part of what I understood to be the power of namespacing in the first place. Am I misunderstanding it?

EDIT: Apparently vbulletin’s php code parser doesn’t like \ in php code blocks. It’s stripping them.

I have asked the same question. As it stands, they just save you from typing a little when you extend or initialise classes. Perhaps someone else can provide some examples that actually provide additional functionality over prefixed classnames (but from what I’ve seen, there’s not).

That’s not to say I dislike them, but from what I can see they don’t really bring anything new functionality wise.

Looks good, I can see what you’re trying to achieve; project specific subclassing.

Keep in mind that this isn’t specific to namespaces and you could do the same with classes named Project_Page and Framework_Page.

Unfortunately, PHP namespaces are rather redundant. If you could do this:

namespace Project;
use \\Framework\\Page as Page;

namespace Project;
class Page {}

and it globally imported page from framework it would give you more power, at any time, you could replace page in the current namespace with a true definition and have it replace the functionality throughout the application. Unfortunately this isn’t possible. Each page controller will have to explicitly state whether it extends \Framework\Page or \Project\Page.

The PHP developers made some odd design decisions with namespaces and I’ve yet to find a proper use for them.

Well, if this is indeed the case, what’s the bloody point in the things other than rudimentary code separation?

I suppose I could bypass the issue by having the autoloader use file_get_contents and then eval the code, but the overhead would be hideous enough to make it unworkable (not to mention the security nightmare).