Posted By

luizlopes on 07/02/08


Tagged

class php include autoload


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

SpinZ
ishkur
dittonamed


Autoloading Objects


 / Published in: PHP
 

URL: http://us3.php.net/__autoload

http://us.php.net/manual/en/language.oop5.autoload.php#82614

  1. <?php
  2. function __autoload($class_name)
  3. {
  4. //class directories
  5. $directorys = array(
  6. 'classes/',
  7. 'classes/otherclasses/',
  8. 'classes2/',
  9. 'module1/classes/'
  10. );
  11.  
  12. //for each directory
  13. foreach($directorys as $directory)
  14. {
  15. //see if the file exsists
  16. if(file_exists($directory.$class_name . '.php'))
  17. {
  18. require_once($directory.$class_name . '.php');
  19. //only require the class once, so quit after to save effort (if you got more, then name them something else
  20. return;
  21. }
  22. }
  23. }
  24. ?>

Report this snippet  

You need to login to post a comment.