cvs: php-src /ext/spl/examples autoload.inc
| From: | Marcus Boerger | Date: | Sun, 02 May 2004 22:55:22 +0000 |
| Subject: | cvs: php-src /ext/spl/examples autoload.inc | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-27243@lists.php.net to get a copy of this message | ||
helly Sun May 2 18:55:22 2004 EDT
Modified files:
/php-src/ext/spl/examples autoload.inc
Log:
- Look for missing classes in include_path
http://cvs.php.net/diff.php/php-src/ext/spl/examples/autoload.inc?r1=1.2&r2=1.3&ty=u
Index: php-src/ext/spl/examples/autoload.inc
diff -u php-src/ext/spl/examples/autoload.inc:1.2 php-src/ext/spl/examples/autoload.inc:1.3
--- php-src/ext/spl/examples/autoload.inc:1.2 Sat Dec 6 14:03:17 2003
+++ php-src/ext/spl/examples/autoload.inc Sun May 2 18:55:22 2004
@@ -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