php-src/ext/spl/examples/autoload.inc
Marcus Boerger 68c22fba72 - Documentation update
- Checkin doxygen config file
# A patched version of doxygen is needed, hopefully 1.3.8 will contain it
2004-05-10 17:26:03 +00:00

50 lines
1.0 KiB
PHP
Executable File

<?php
/** @file autoload.inc
* @ingroup Examples
* @brief function __autoload
* @author Marcus Boerger
* @date 2003 - 2004
*
* SPL - Standard PHP Library
*/
/** \internal
* Tries to load class $classname from directory $dir.
*/
function __load_class($classname, $dir)
{
$file = $dir . '/' . $classname . '.inc';
if (file_exists($file))
{
require_once($file);
return true;
}
return false;
}
/**
* @brief Class loader for SPL example classes
* @author Marcus Boerger
* @version 1.0
*
* Loads classes automatically from include_path as given by ini or from
* current directory of script or include file.
*/
function __autoload($classname) {
$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;
}
?>