__autoload detecting and including interfaces

godosrats

New Member
I am using __autoload in my script to include classes as needed. My script uses cues in the class name to find the file containing it. If it ends in model it is in the model directory, controllers are in the controller directory, etc. I am starting to implement interfaces, and so need to adjust my autoloader.Ideally, when an object is created the autoloader would determine the file-name of the object, where it is stored, and include the file. Then it would interrogate that class for what interfaces it implements, and then include those files automatically.Something like\[code\]function __autoload($classname){ echo $classname; include ("classes/$classname.php"); $interfaces = class_implements($classname,FALSE); foreach($interfaces as $name){ if(!class_exists($name,FALSE)){ include("interfaces/".$name."inter.php"); } }}\[/code\]Except when I do that I get the error\[quote\] Cannot redeclare __autoload() (previously declared in W:\xampp\htdocs\test\auto.php:5) in W:\xampp\htdocs\test\auto.php on line 11\[/quote\]is it not possible to do this in the __autoload()? Should I just continue relying on naming conventions to differentiate between types of objects and where they are stored?
 
Top