Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #25408 [Debug] Fix catching fatal errors in case of nested error …
…handlers (nicolas-grekas) This PR was merged into the 2.7 branch. Discussion ---------- [Debug] Fix catching fatal errors in case of nested error handlers | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8703, #16980 | License | MIT | Doc PR | - Fixing a bug from 2013 :) Commits ------- 27dc9a6 [Debug] Fix catching fatal errors in case of nested error handlers
- Loading branch information
Showing
3 changed files
with
106 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Symfony/Component/Debug/Tests/phpt/exception_rethrown.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
Test rethrowing in custom exception handler | ||
--FILE-- | ||
<?php | ||
|
||
namespace Symfony\Component\Debug; | ||
|
||
$vendor = __DIR__; | ||
while (!file_exists($vendor.'/vendor')) { | ||
$vendor = dirname($vendor); | ||
} | ||
require $vendor.'/vendor/autoload.php'; | ||
|
||
if (true) { | ||
class TestLogger extends \Psr\Log\AbstractLogger | ||
{ | ||
public function log($level, $message, array $context = array()) | ||
{ | ||
echo $message, "\n"; | ||
} | ||
} | ||
} | ||
|
||
set_exception_handler(function ($e) { echo 123; throw $e; }); | ||
ErrorHandler::register()->setDefaultLogger(new TestLogger()); | ||
ini_set('display_errors', 1); | ||
|
||
throw new \Exception('foo'); | ||
|
||
?> | ||
--EXPECTF-- | ||
Uncaught Exception: foo | ||
123 | ||
Fatal error: Uncaught %s:25 | ||
Stack trace: | ||
%a |
40 changes: 40 additions & 0 deletions
40
src/Symfony/Component/Debug/Tests/phpt/fatal_with_nested_handlers.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--TEST-- | ||
Test catching fatal errors when handlers are nested | ||
--FILE-- | ||
<?php | ||
|
||
namespace Symfony\Component\Debug; | ||
|
||
$vendor = __DIR__; | ||
while (!file_exists($vendor.'/vendor')) { | ||
$vendor = dirname($vendor); | ||
} | ||
require $vendor.'/vendor/autoload.php'; | ||
|
||
Debug::enable(); | ||
ini_set('display_errors', 0); | ||
|
||
$eHandler = set_error_handler('var_dump'); | ||
$xHandler = set_exception_handler('var_dump'); | ||
|
||
var_dump(array( | ||
$eHandler[0] === $xHandler[0] ? 'Error and exception handlers do match' : 'Error and exception handlers are different', | ||
)); | ||
|
||
$eHandler[0]->setExceptionHandler('print_r'); | ||
|
||
if (true) { | ||
class Broken implements \Serializable {}; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
array(1) { | ||
[0]=> | ||
string(37) "Error and exception handlers do match" | ||
} | ||
object(Symfony\Component\Debug\Exception\FatalErrorException)#4 (8) { | ||
["message":protected]=> | ||
string(199) "Error: Class Symfony\Component\Debug\Broken contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Serializable::serialize, Serializable::unserialize)" | ||
%a | ||
} |