038.phpt 744 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Convert warnings to exceptions
  3. --FILE--
  4. <?php
  5. class MyException extends Exception
  6. {
  7. function __construct($errstr, $errno=0, $errfile='', $errline=0)
  8. {
  9. parent::__construct($errstr, $errno);
  10. $this->file = $errfile;
  11. $this->line = $errline;
  12. }
  13. }
  14. function Error2Exception($errno, $errstr, $errfile, $errline)
  15. {
  16. throw new MyException($errstr, $errno);//, $errfile, $errline);
  17. }
  18. $err_msg = 'no exception';
  19. set_error_handler('Error2Exception');
  20. try
  21. {
  22. $con = fopen("/tmp/a_file_that_does_not_exist",'r');
  23. }
  24. catch (Exception $e)
  25. {
  26. $trace = $e->getTrace();
  27. var_dump($trace[0]['function']);
  28. var_dump($trace[1]['function']);
  29. }
  30. ?>
  31. --EXPECT--
  32. string(15) "Error2Exception"
  33. string(5) "fopen"