autoload.inc 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /** @file autoload.inc
  3. * @ingroup Examples
  4. * @brief function __autoload
  5. * @author Marcus Boerger
  6. * @date 2003 - 2005
  7. *
  8. * SPL - Standard PHP Library
  9. */
  10. /** \internal
  11. * Tries to load class $classname from directory $dir.
  12. */
  13. function __load_class($classname, $dir)
  14. {
  15. $file = $dir . '/' . $classname . '.inc';
  16. if (file_exists($file))
  17. {
  18. require_once($file);
  19. return true;
  20. }
  21. return false;
  22. }
  23. /**
  24. * @brief Class loader for SPL example classes
  25. * @author Marcus Boerger
  26. * @version 1.0
  27. *
  28. * Loads classes automatically from include_path as given by ini or from
  29. * current directory of script or include file.
  30. */
  31. function __autoload($classname) {
  32. $classname = strtolower($classname);
  33. $inc = split(':', ini_get('include_path'));
  34. $inc[] = '.';
  35. $inc[] = dirname($_SERVER['PATH_TRANSLATED']);
  36. foreach($inc as $dir)
  37. {
  38. if (__load_class($classname, $dir))
  39. {
  40. fprintf(STDERR, 'Loading class('.$classname.")\n");
  41. return;
  42. }
  43. }
  44. fprintf(STDERR, 'Class not found ('.$classname.")\n");
  45. }
  46. ?>