xref: /PHP-5.5/ext/spl/tests/spl_autoload_005.phpt (revision 610c7fbe)
1--TEST--
2SPL: spl_autoload() with methods
3--INI--
4include_path=.
5--FILE--
6<?php
7
8class MyAutoLoader {
9
10        function autoLoad($className)
11        {
12        	echo __METHOD__ . "($className)\n";
13        }
14
15        function autoThrow($className)
16        {
17        	echo __METHOD__ . "($className)\n";
18        	throw new Exception("Unavailable");
19        }
20}
21
22try
23{
24	spl_autoload_register(array('MyAutoLoader', 'autoLoad'), true);
25}
26catch(Exception $e)
27{
28	echo 'Exception: ' . $e->getMessage() . "\n";
29}
30
31// and
32
33$myAutoLoader = new MyAutoLoader();
34
35spl_autoload_register(array($myAutoLoader, 'autoLoad'));
36spl_autoload_register(array($myAutoLoader, 'autoThrow'));
37
38try
39{
40	var_dump(class_exists("TestClass", true));
41}
42catch(Exception $e)
43{
44	echo 'Exception: ' . $e->getMessage() . "\n";
45}
46
47?>
48===DONE===
49<?php exit(0); ?>
50--EXPECTF--
51Exception: Passed array specifies a non static method but no object (non-static method MyAutoLoader::autoLoad() should not be called statically)
52MyAutoLoader::autoLoad(TestClass)
53MyAutoLoader::autoThrow(TestClass)
54Exception: Unavailable
55===DONE===
56