summaryrefslogtreecommitdiff
path: root/ext/spl/examples/autoload.inc
blob: c2c4222f857cef0e2b7e9192ee2846ae79e50d27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

/** \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;
}

?>