Skip to content

Commit 708de1f

Browse files
Jean85nicolas-grekas
authored andcommitted
Add regression test case for #26438
1 parent 011c50c commit 708de1f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
namespace Symfony\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+
private static $prevErrorHandler;
17+
private static $prevExceptionHandler;
18+
19+
public static function register()
20+
{
21+
static::$prevErrorHandler = set_error_handler(array(__CLASS__, 'handleError'));
22+
static::$prevExceptionHandler = set_exception_handler(array(__CLASS__, 'handleException'));
23+
}
24+
25+
public static function handleError($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+
return call_user_func(static::$prevErrorHandler, $type, $message, $file, $line);
30+
}
31+
32+
public static function handleException($e)
33+
{
34+
echo 'Third party exception handler' . PHP_EOL;
35+
echo 'Calling previous handler: ' . get_class(static::$prevExceptionHandler[0]) . PHP_EOL;
36+
return call_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

0 commit comments

Comments
 (0)