1--TEST-- 2SPL: spl_autoload() with inaccessible methods 3--INI-- 4include_path=. 5--FILE-- 6<?php 7 8class MyAutoLoader { 9 10 static protected function noAccess($className) { 11 echo __METHOD__ . "($className)\n"; 12 } 13 14 static function autoLoad($className) { 15 echo __METHOD__ . "($className)\n"; 16 } 17 18 function dynaLoad($className) { 19 echo __METHOD__ . "($className)\n"; 20 } 21} 22 23$obj = new MyAutoLoader; 24 25$funcs = array( 26 'MyAutoLoader::notExist', 27 'MyAutoLoader::noAccess', 28 'MyAutoLoader::autoLoad', 29 'MyAutoLoader::dynaLoad', 30 array('MyAutoLoader', 'notExist'), 31 array('MyAutoLoader', 'noAccess'), 32 array('MyAutoLoader', 'autoLoad'), 33 array('MyAutoLoader', 'dynaLoad'), 34 array($obj, 'notExist'), 35 array($obj, 'noAccess'), 36 array($obj, 'autoLoad'), 37 array($obj, 'dynaLoad'), 38); 39 40foreach($funcs as $idx => $func) 41{ 42 if ($idx) echo "\n"; 43 try 44 { 45 var_dump($func); 46 spl_autoload_register($func); 47 echo "ok\n"; 48 } 49 catch (Exception $e) 50 { 51 echo $e->getMessage() . "\n"; 52 } 53} 54 55?> 56===DONE=== 57<?php exit(0); ?> 58--EXPECTF-- 59string(22) "MyAutoLoader::notExist" 60Function 'MyAutoLoader::notExist' not found (class 'MyAutoLoader' does not have a method 'notExist') 61 62string(22) "MyAutoLoader::noAccess" 63Function 'MyAutoLoader::noAccess' not callable (cannot access protected method MyAutoLoader::noAccess()) 64 65string(22) "MyAutoLoader::autoLoad" 66ok 67 68string(22) "MyAutoLoader::dynaLoad" 69Function 'MyAutoLoader::dynaLoad' not callable (non-static method MyAutoLoader::dynaLoad() should not be called statically) 70 71array(2) { 72 [0]=> 73 string(12) "MyAutoLoader" 74 [1]=> 75 string(8) "notExist" 76} 77Passed array does not specify an existing static method (class 'MyAutoLoader' does not have a method 'notExist') 78 79array(2) { 80 [0]=> 81 string(12) "MyAutoLoader" 82 [1]=> 83 string(8) "noAccess" 84} 85Passed array does not specify a callable static method (cannot access protected method MyAutoLoader::noAccess()) 86 87array(2) { 88 [0]=> 89 string(12) "MyAutoLoader" 90 [1]=> 91 string(8) "autoLoad" 92} 93ok 94 95array(2) { 96 [0]=> 97 string(12) "MyAutoLoader" 98 [1]=> 99 string(8) "dynaLoad" 100} 101Passed array specifies a non static method but no object (non-static method MyAutoLoader::dynaLoad() should not be called statically) 102 103array(2) { 104 [0]=> 105 object(MyAutoLoader)#%d (0) { 106 } 107 [1]=> 108 string(8) "notExist" 109} 110Passed array does not specify an existing method (class 'MyAutoLoader' does not have a method 'notExist') 111 112array(2) { 113 [0]=> 114 object(MyAutoLoader)#%d (0) { 115 } 116 [1]=> 117 string(8) "noAccess" 118} 119Passed array does not specify a callable method (cannot access protected method MyAutoLoader::noAccess()) 120 121array(2) { 122 [0]=> 123 object(MyAutoLoader)#%d (0) { 124 } 125 [1]=> 126 string(8) "autoLoad" 127} 128ok 129 130array(2) { 131 [0]=> 132 object(MyAutoLoader)#%d (0) { 133 } 134 [1]=> 135 string(8) "dynaLoad" 136} 137ok 138===DONE=== 139