spl_autoload_005.phpt 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --TEST--
  2. SPL: spl_autoload() with methods
  3. --INI--
  4. include_path=.
  5. --FILE--
  6. <?php
  7. class MyAutoLoader {
  8. function autoLoad($className)
  9. {
  10. echo __METHOD__ . "($className)\n";
  11. }
  12. function autoThrow($className)
  13. {
  14. echo __METHOD__ . "($className)\n";
  15. throw new Exception("Unavailable");
  16. }
  17. }
  18. try {
  19. spl_autoload_register(array('MyAutoLoader', 'autoLoad'), true);
  20. } catch(\TypeError $e) {
  21. echo $e->getMessage() . \PHP_EOL;
  22. }
  23. // and
  24. $myAutoLoader = new MyAutoLoader();
  25. spl_autoload_register(array($myAutoLoader, 'autoLoad'));
  26. spl_autoload_register(array($myAutoLoader, 'autoThrow'));
  27. try
  28. {
  29. var_dump(class_exists("TestClass", true));
  30. }
  31. catch(Exception $e)
  32. {
  33. echo 'Exception: ' . $e->getMessage() . "\n";
  34. }
  35. ?>
  36. --EXPECT--
  37. spl_autoload_register(): Argument #1 ($callback) must be a valid callback or null, non-static method MyAutoLoader::autoLoad() cannot be called statically
  38. MyAutoLoader::autoLoad(TestClass)
  39. MyAutoLoader::autoThrow(TestClass)
  40. Exception: Unavailable