summaryrefslogtreecommitdiff
path: root/ext/spl/examples/autoload.inc
blob: 430680645acc40c59ee529b1e6f9a4da7ed57967 (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
<?php

function __load_class($classname, $dir)
{
	$file = $dir . '/' . $classname . '.inc';
	if (file_exists($file))
	{
		require_once($file);
		return true;
	}
	return false;
}

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;
}

?>