]> granicus.if.org Git - php/commitdiff
- Look for missing classes in include_path
authorMarcus Boerger <helly@php.net>
Sun, 2 May 2004 22:55:22 +0000 (22:55 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 2 May 2004 22:55:22 +0000 (22:55 +0000)
ext/spl/examples/autoload.inc

index 34072f8e4a6b0de359d7ce5715f5fa9b4cc76ea9..430680645acc40c59ee529b1e6f9a4da7ed57967 100755 (executable)
@@ -1,7 +1,30 @@
 <?php
 
+function __load_class($classname, $dir)
+{
+       $file = $dir . '/' . $classname . '.inc';
+       if (file_exists($file))
+       {
+               require_once($file);
+               return true;
+       }
+       return false;
+}
+
 function __autoload($classname) {
-       require_once(dirname($_SERVER['PATH_TRANSLATED']).'/'.strtolower($classname).'.inc');
+       $classname = strtolower($classname);
+       foreach(split(':', ini_get('include_path')) as $dir)
+       {
+               if (__load_class($classname, $dir))
+               {
+                       fprintf(STDERR, 'Loading class('.$classname.")\n");
+                       return;
+               }
+       }
+       if (!__load_class($classname, '.'))
+       if (!__load_class($classname, dirname($_SERVER['PATH_TRANSLATED'])))
+       fprintf(STDERR, 'Class not found ('.$classname.")\n");
+       return;
 }
 
 ?>
\ No newline at end of file