Skip to content

Commit 33050e3

Browse files
Merge branch '5.4' into 6.4
* 5.4: Tweak error/exception handler registration
2 parents 4b2ebd9 + de1a6ac commit 33050e3

File tree

8 files changed

+55
-27
lines changed

8 files changed

+55
-27
lines changed

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
5959
use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass;
6060
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
61+
use Symfony\Component\Runtime\SymfonyRuntime;
6162
use Symfony\Component\Scheduler\DependencyInjection\AddScheduleMessengerPass;
6263
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
6364
use Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass;
@@ -99,13 +100,19 @@ public function boot()
99100
{
100101
$_ENV['DOCTRINE_DEPRECATIONS'] = $_SERVER['DOCTRINE_DEPRECATIONS'] ??= 'trigger';
101102

102-
$handler = ErrorHandler::register(null, false);
103+
if (class_exists(SymfonyRuntime::class)) {
104+
$handler = set_error_handler('var_dump');
105+
restore_error_handler();
106+
} else {
107+
$handler = [ErrorHandler::register(null, false)];
108+
}
103109

104-
// When upgrading an existing Symfony application from 6.2 to 6.3, and
105-
// the cache is warmed up, the service is not available yet, so we need
106-
// to check if it exists.
107-
if ($this->container->has('debug.error_handler_configurator')) {
108-
$this->container->get('debug.error_handler_configurator')->configure($handler);
110+
if (!$this->container->has('debug.error_handler_configurator')) {
111+
// When upgrading an existing Symfony application from 6.2 to 6.3, and
112+
// the cache is warmed up, the service is not available yet, so we need
113+
// to check if it exists.
114+
} elseif (\is_array($handler) && $handler[0] instanceof ErrorHandler) {
115+
$this->container->get('debug.error_handler_configurator')->configure($handler[0]);
109116
}
110117

111118
if ($this->container->getParameter('kernel.http_method_override')) {

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"symfony/mime": "<6.4",
9494
"symfony/property-info": "<5.4",
9595
"symfony/property-access": "<5.4",
96+
"symfony/runtime": "<5.4.45|>=6.0,<6.4.13|>=7.0,<7.1.6",
9697
"symfony/scheduler": "<6.4.4|>=7.0.0,<7.0.4",
9798
"symfony/serializer": "<6.4",
9899
"symfony/security-csrf": "<5.4",

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
169169
}
170170
}
171171

172-
$this->configureIO($input, $output);
173-
174172
try {
173+
$this->configureIO($input, $output);
174+
175175
$exitCode = $this->doRun($input, $output);
176176
} catch (\Throwable $e) {
177177
if ($e instanceof \Exception && !$this->catchExceptions) {

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public function __construct(?callable $exceptionHandler = null, bool|LoggerInter
4747
// BC with Symfony 5
4848
$webMode = null;
4949
}
50-
$handler = set_exception_handler('is_int');
50+
51+
$handler = set_exception_handler('var_dump');
5152
$this->earlyHandler = \is_array($handler) ? $handler[0] : null;
5253
restore_exception_handler();
5354

@@ -94,7 +95,7 @@ public function configure(?object $event = null): void
9495
}
9596
}
9697
if ($this->exceptionHandler) {
97-
$handler = set_exception_handler(static fn () => null);
98+
$handler = set_exception_handler('var_dump');
9899
$handler = \is_array($handler) ? $handler[0] : null;
99100
restore_exception_handler();
100101

src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ public function onKernelException(ExceptionEvent $event)
104104

105105
$throwable = $event->getThrowable();
106106

107-
if ($exceptionHandler = set_exception_handler(var_dump(...))) {
108-
restore_exception_handler();
109-
if (\is_array($exceptionHandler) && $exceptionHandler[0] instanceof ErrorHandler) {
110-
$throwable = $exceptionHandler[0]->enhanceError($event->getThrowable());
111-
}
107+
$exceptionHandler = set_exception_handler('var_dump');
108+
restore_exception_handler();
109+
110+
if (\is_array($exceptionHandler) && $exceptionHandler[0] instanceof ErrorHandler) {
111+
$throwable = $exceptionHandler[0]->enhanceError($event->getThrowable());
112112
}
113113

114114
$request = $this->duplicateRequest($throwable, $event->getRequest());

src/Symfony/Component/Runtime/GenericRuntime.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ public function __construct(array $options = [])
7171
if ($debug) {
7272
umask(0000);
7373
$_SERVER[$debugKey] = $_ENV[$debugKey] = '1';
74-
75-
if (false !== $errorHandler = ($options['error_handler'] ?? BasicErrorHandler::class)) {
76-
$errorHandler::register($debug);
77-
$options['error_handler'] = false;
78-
}
7974
} else {
8075
$_SERVER[$debugKey] = $_ENV[$debugKey] = '0';
8176
}
8277

78+
if (false !== $errorHandler = ($options['error_handler'] ?? BasicErrorHandler::class)) {
79+
$errorHandler::register($debug);
80+
$options['error_handler'] = false;
81+
}
82+
8383
$this->options = $options;
8484
}
8585

src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public static function register(bool $debug): void
3030
}
3131

3232
if (0 <= \ini_get('zend.assertions')) {
33-
ini_set('zend.assertions', 1);
34-
ini_set('assert.active', $debug);
35-
ini_set('assert.exception', 1);
33+
ini_set('zend.assertions', (int) $debug);
3634
}
35+
ini_set('assert.active', 1);
36+
ini_set('assert.exception', 1);
3737

3838
set_error_handler(new self());
3939
}

src/Symfony/Component/Runtime/Internal/SymfonyErrorHandler.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,31 @@ class SymfonyErrorHandler
2424
{
2525
public static function register(bool $debug): void
2626
{
27-
BasicErrorHandler::register($debug);
27+
if (!class_exists(ErrorHandler::class)) {
28+
BasicErrorHandler::register($debug);
2829

29-
if (class_exists(ErrorHandler::class)) {
30+
return;
31+
}
32+
33+
error_reporting(-1);
34+
35+
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
36+
ini_set('display_errors', $debug);
37+
} elseif (!filter_var(\ini_get('log_errors'), \FILTER_VALIDATE_BOOL) || \ini_get('error_log')) {
38+
// CLI - display errors only if they're not already logged to STDERR
39+
ini_set('display_errors', 1);
40+
}
41+
42+
if (0 <= \ini_get('zend.assertions')) {
43+
ini_set('zend.assertions', (int) $debug);
44+
}
45+
ini_set('assert.active', 1);
46+
ini_set('assert.exception', 1);
47+
48+
if ($debug) {
3049
DebugClassLoader::enable();
31-
restore_error_handler();
32-
ErrorHandler::register(new ErrorHandler(new BufferingLogger(), $debug));
3350
}
51+
52+
ErrorHandler::register(new ErrorHandler(new BufferingLogger(), $debug));
3453
}
3554
}

0 commit comments

Comments
 (0)