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 spl_autoload_register(array('MyAutoLoader', 'autoLoad'), true); 24} catch(\TypeError $e) { 25 echo $e->getMessage() . \PHP_EOL; 26} 27 28// and 29 30$myAutoLoader = new MyAutoLoader(); 31 32spl_autoload_register(array($myAutoLoader, 'autoLoad')); 33spl_autoload_register(array($myAutoLoader, 'autoThrow')); 34 35try 36{ 37 var_dump(class_exists("TestClass", true)); 38} 39catch(Exception $e) 40{ 41 echo 'Exception: ' . $e->getMessage() . "\n"; 42} 43 44?> 45--EXPECT-- 46spl_autoload_register(): Argument #1 ($callback) must be a valid callback, non-static method MyAutoLoader::autoLoad() cannot be called statically 47MyAutoLoader::autoLoad(TestClass) 48MyAutoLoader::autoThrow(TestClass) 49Exception: Unavailable 50