|
| 1 | +--TEST-- |
| 2 | +Test that, when handling a fatal, we don't create a loop with a third party exception handler installed after ours |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | + |
| 6 | +namespaceSymfony\Component\Debug; |
| 7 | + |
| 8 | +$vendor =__DIR__; |
| 9 | +while (!file_exists($vendor.'/vendor')) { |
| 10 | +$vendor =dirname($vendor); |
| 11 | +} |
| 12 | +require$vendor.'/vendor/autoload.php'; |
| 13 | + |
| 14 | +class ThirdPartyExceptionHandler |
| 15 | +{ |
| 16 | +privatestatic$prevErrorHandler; |
| 17 | +privatestatic$prevExceptionHandler; |
| 18 | + |
| 19 | +publicstaticfunctionregister() |
| 20 | + { |
| 21 | +static::$prevErrorHandler =set_error_handler(array(__CLASS__,'handleError')); |
| 22 | +static::$prevExceptionHandler =set_exception_handler(array(__CLASS__,'handleException')); |
| 23 | + } |
| 24 | + |
| 25 | +publicstaticfunctionhandleError($type,$message,$file,$line) |
| 26 | + { |
| 27 | +echo'Third party error handler' .PHP_EOL; |
| 28 | +echo'Calling previous handler:' .get_class(static::$prevErrorHandler[0]) .PHP_EOL; |
| 29 | +returncall_user_func(static::$prevErrorHandler,$type,$message,$file,$line); |
| 30 | + } |
| 31 | + |
| 32 | +publicstaticfunctionhandleException($e) |
| 33 | + { |
| 34 | +echo'Third party exception handler' .PHP_EOL; |
| 35 | +echo'Calling previous handler:' .get_class(static::$prevExceptionHandler[0]) .PHP_EOL; |
| 36 | +returncall_user_func(static::$prevExceptionHandler,$e); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +ErrorHandler::register(); |
| 41 | +ThirdPartyExceptionHandler::register(); |
| 42 | +ini_set('display_errors',1); |
| 43 | + |
| 44 | +$a =null; |
| 45 | +require'inexistent_file.php'; |
| 46 | +?> |
| 47 | +--EXPECTF-- |
| 48 | +Third party error handler |
| 49 | +Calling previous handler: Symfony\Component\Debug\ErrorHandler |
| 50 | +%a |
| 51 | +Fatal error: main(): Failed opening required 'inexistent_file.php'%s |
| 52 | +Third party exception handler |
| 53 | +Calling previous handler: Symfony\Component\Debug\ErrorHandler |