spl_autoload_005.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. {
  20. spl_autoload_register(array('MyAutoLoader', 'autoLoad'), true);
  21. }
  22. catch(Exception $e)
  23. {
  24. echo 'Exception: ' . $e->getMessage() . "\n";
  25. }
  26. // and
  27. $myAutoLoader = new MyAutoLoader();
  28. spl_autoload_register(array($myAutoLoader, 'autoLoad'));
  29. spl_autoload_register(array($myAutoLoader, 'autoThrow'));
  30. try
  31. {
  32. var_dump(class_exists("TestClass", true));
  33. }
  34. catch(Exception $e)
  35. {
  36. echo 'Exception: ' . $e->getMessage() . "\n";
  37. }
  38. ?>
  39. ===DONE===
  40. <?php exit(0); ?>
  41. --EXPECTF--
  42. Exception: Passed array specifies a non static method but no object (non-static method MyAutoLoader::autoLoad() should not be called statically)
  43. MyAutoLoader::autoLoad(TestClass)
  44. MyAutoLoader::autoThrow(TestClass)
  45. Exception: Unavailable
  46. ===DONE===