039.phpt 698 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Catch Interfaces
  3. --FILE--
  4. <?php
  5. interface Catchable
  6. {
  7. }
  8. class MyException extends Exception implements Catchable
  9. {
  10. function __construct($errstr, $errno, $errfile, $errline)
  11. {
  12. parent::__construct($errstr, $errno);
  13. $this->file = $errfile;
  14. $this->line = $errline;
  15. }
  16. }
  17. function Error2Exception($errno, $errstr, $errfile, $errline)
  18. {
  19. throw new MyException($errstr, $errno, $errfile, $errline);
  20. }
  21. $err_msg = 'no exception';
  22. set_error_handler('Error2Exception');
  23. try
  24. {
  25. $con = fopen('/tmp/a_file_that_does_not_exist','r');
  26. }
  27. catch (Catchable $e)
  28. {
  29. echo "Catchable\n";
  30. }
  31. catch (Exception $e)
  32. {
  33. echo "Exception\n";
  34. }
  35. ?>
  36. --EXPECT--
  37. Catchable