Annotation of embedaddon/php/ext/spl/tests/spl_autoload_001.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: SPL: spl_autoload() and friends
3: --INI--
4: include_path=.
5: --FILE--
6: <?php
7:
8: echo "===EMPTY===\n";
9:
10: var_dump(spl_autoload_extensions());
11:
12: try
13: {
14: spl_autoload("TestClass");
15: }
16: catch(Exception $e)
17: {
18: echo 'Exception: ' . $e->getMessage() . "\n";
19: }
20:
21: $test_exts = array(NULL, "1", ".inc,,.php.inc", "");
22:
23: foreach($test_exts as $exts)
24: {
25: echo "===($exts)===\n";
26: try
27: {
28: spl_autoload("TestClass", $exts);
29: }
30: catch(Exception $e)
31: {
32: echo 'Exception: ' . $e->getMessage() . "\n";
33: }
34: }
35:
36: try
37: {
38: spl_autoload_extensions(".inc,.php.inc");
39: spl_autoload("TestClass");
40: }
41: catch(Exception $e)
42: {
43: echo 'Exception: ' . $e->getMessage() . "\n";
44: }
45:
46: function TestFunc1($classname)
47: {
48: echo __METHOD__ . "($classname)\n";
49: }
50:
51: function TestFunc2($classname)
52: {
53: echo __METHOD__ . "($classname)\n";
54: }
55:
56: echo "===SPL_AUTOLOAD()===\n";
57:
58: spl_autoload_register();
59:
60: try
61: {
62: var_dump(spl_autoload_extensions(".inc"));
63: var_dump(class_exists("TestClass", true));
64: }
65: catch(Exception $e)
66: {
67: echo 'Exception: ' . $e->getMessage() . "\n";
68: }
69:
70: echo "===REGISTER===\n";
71:
72: spl_autoload_unregister("spl_autoload");
73: spl_autoload_register("TestFunc1");
74: spl_autoload_register("TestFunc2");
75: spl_autoload_register("TestFunc2"); /* 2nd call ignored */
76: spl_autoload_extensions(".inc,.class.inc"); /* we do not have spl_autoload_registered yet */
77:
78: try
79: {
80: var_dump(class_exists("TestClass", true));
81: }
82: catch(Exception $e)
83: {
84: echo 'Exception: ' . $e->getMessage() . "\n";
85: }
86:
87: echo "===LOAD===\n";
88:
89: spl_autoload_register("spl_autoload");
90: var_dump(class_exists("TestClass", true));
91:
92: echo "===NOFUNCTION===\n";
93:
94: try
95: {
96: spl_autoload_register("unavailable_autoload_function");
97: }
98: catch(Exception $e)
99: {
100: echo 'Exception: ' . $e->getMessage() . "\n";
101: }
102:
103: ?>
104: ===DONE===
105: <?php exit(0); ?>
106: --EXPECTF--
107: ===EMPTY===
108: string(9) ".inc,.php"
109: %stestclass.inc
110: Exception: Class TestClass could not be loaded
111: ===()===
112: Exception: Class TestClass could not be loaded
113: ===(1)===
114: Exception: Class TestClass could not be loaded
115: ===(.inc,,.php.inc)===
116: %stestclass
117: %stestclass.php.inc
118: Exception: Class TestClass could not be loaded
119: ===()===
120: Exception: Class TestClass could not be loaded
121: Exception: Class TestClass could not be loaded
122: ===SPL_AUTOLOAD()===
123: string(4) ".inc"
124: Exception: Class TestClass could not be loaded
125: ===REGISTER===
126: TestFunc1(TestClass)
127: TestFunc2(TestClass)
128: bool(false)
129: ===LOAD===
130: TestFunc1(TestClass)
131: TestFunc2(TestClass)
132: %stestclass.class.inc
133: bool(true)
134: ===NOFUNCTION===
135: Exception: Function 'unavailable_autoload_function' not found (function 'unavailable_autoload_function' not found or invalid function name)
136: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>