spl_autoload_012.phpt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --TEST--
  2. SPL: spl_autoload() capturing multiple Exceptions in __autoload
  3. --FILE--
  4. <?php
  5. function autoload_first($name)
  6. {
  7. echo __METHOD__ . "\n";
  8. throw new Exception('first');
  9. }
  10. function autoload_second($name)
  11. {
  12. echo __METHOD__ . "\n";
  13. throw new Exception('second');
  14. }
  15. spl_autoload_register('autoload_first');
  16. spl_autoload_register('autoload_second');
  17. try {
  18. class_exists('ThisClassDoesNotExist');
  19. } catch(Exception $e) {
  20. do {
  21. echo $e->getMessage()."\n";
  22. } while($e = $e->getPrevious());
  23. }
  24. try {
  25. new ThisClassDoesNotExist;
  26. } catch(Exception $e) {
  27. do {
  28. echo $e->getMessage()."\n";
  29. } while($e = $e->getPrevious());
  30. }
  31. class_exists('ThisClassDoesNotExist');
  32. ?>
  33. ===DONE===
  34. --EXPECTF--
  35. autoload_first
  36. autoload_second
  37. second
  38. first
  39. autoload_first
  40. autoload_second
  41. second
  42. first
  43. autoload_first
  44. autoload_second
  45. Fatal error: Uncaught exception 'Exception' with message 'first' in %sspl_autoload_012.php:%d
  46. Stack trace:
  47. #0 [internal function]: autoload_first('ThisClassDoesNo...')
  48. #1 [internal function]: spl_autoload_call('ThisClassDoesNo...')
  49. #2 %sspl_autoload_012.php(%d): class_exists('ThisClassDoesNo...')
  50. #3 {main}
  51. Next exception 'Exception' with message 'second' in %sspl_autoload_012.php:%d
  52. Stack trace:
  53. #0 [internal function]: autoload_second('ThisClassDoesNo...')
  54. #1 [internal function]: spl_autoload_call('ThisClassDoesNo...')
  55. #2 %sspl_autoload_012.php(%d): class_exists('ThisClassDoesNo...')
  56. #3 {main}
  57. thrown in %sspl_autoload_012.php on line %d