tags:

views:

20

answers:

2

Is there a manner in which to catch requests to a class which does not exist.

I'm looking for something exactly like __call() and __static(), but for classes as opposed to methods in a class.

I am not talking about autoloading. I need to be able to interrupt the request and reroute it.

Ideas?

+2  A: 

I am not aware of any way of intercepting

$variable = new Classname();

without extremely resource-draining things like Reflection or parsing the script files before executing them.

As far as I can see, autoloading is the closest you'll get here.

If you need to do this, you may have to build a custom factory function

$variable = newClass("Classname", $arg1, $arg2, $arg3);

and do your intercepting there.

Pekka
I was afraid of this. Yeah a factory is not quite viable in this case. It's not required to move forward, but would be a bit cleaner. Thanks for the feedback.
Spot
+2  A: 

I am not talking about autoloading. I need to be able to interrupt the request and reroute it.

Ideas?

I'm not convinced autoload can't do what you need. If a request comes in for an undefined class, autoload can load the appropriate class file which would contain a class that has a combination of reflection and _call/_get, etc... and be able to process the request.

webbiedave
+1. You could probably even create a stub class from within autoload, provided you're not planning on actually loading the real class later.
Frank Farmer