summaryrefslogtreecommitdiff
path: root/ext/spl/tests/spl_autoload_005.phpt
blob: 58c4d7ca8fa91f52e1ec661ea5c5d85abdb775af (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--TEST--
SPL: spl_autoload() with methods
--INI--
include_path=.
--FILE--
<?php

class MyAutoLoader {

        function autoLoad($className)
        {
        	echo __METHOD__ . "($className)\n";
        }

        function autoThrow($className)
        {
        	echo __METHOD__ . "($className)\n";
        	throw new Exception("Unavailable");
        }
}

try
{
	spl_autoload_register(array('MyAutoLoader', 'autoLoad'), true);
}
catch(Exception $e)
{
	echo 'Exception: ' . $e->getMessage() . "\n";
}

// and

$myAutoLoader = new MyAutoLoader();

spl_autoload_register(array($myAutoLoader, 'autoLoad'));
spl_autoload_register(array($myAutoLoader, 'autoThrow'));

try
{
	var_dump(class_exists("TestClass", true));
}
catch(Exception $e)
{
	echo 'Exception: ' . $e->getMessage() . "\n";
}

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
Exception: Passed array specifies a non static method but no object (non-static method MyAutoLoader::autoLoad() should not be called statically)
MyAutoLoader::autoLoad(TestClass)
MyAutoLoader::autoThrow(TestClass)
Exception: Unavailable
===DONE===