diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 2197610896eb5..1aebc9b9a4b0b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -60,6 +60,7 @@ use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass; use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass; use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass; +use Symfony\Component\Runtime\SymfonyRuntime; use Symfony\Component\Serializer\DependencyInjection\SerializerPass; use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass; use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass; @@ -91,7 +92,16 @@ class FrameworkBundle extends Bundle { public function boot() { - ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true); + if (class_exists(SymfonyRuntime::class)) { + $handler = set_error_handler('var_dump'); + restore_error_handler(); + } else { + $handler = [ErrorHandler::register(null, false)]; + } + + if (\is_array($handler) && $handler[0] instanceof ErrorHandler) { + $handler[0]->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true); + } if ($this->container->getParameter('kernel.http_method_override')) { Request::enableHttpMethodParameterOverride(); diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 3bae1c3862618..f5b156df49f9b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -86,6 +86,7 @@ "symfony/mime": "<4.4", "symfony/property-info": "<4.4", "symfony/property-access": "<5.3", + "symfony/runtime": "<5.4.45|>=6.0,<6.4.13|>=7.0,<7.1.6", "symfony/serializer": "<5.2", "symfony/service-contracts": ">=3.0", "symfony/security-csrf": "<5.3", diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index bb5341882181a..fbb3b0eb009a7 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -165,9 +165,9 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu } } - $this->configureIO($input, $output); - try { + $this->configureIO($input, $output); + $exitCode = $this->doRun($input, $output); } catch (\Exception $e) { if (!$this->catchExceptions) { diff --git a/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php b/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php index 74fa6179480ed..791fda7d83a9d 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php @@ -57,7 +57,7 @@ public function __construct(?callable $exceptionHandler = null, ?LoggerInterface $deprecationLogger = $fileLinkFormat; } - $handler = set_exception_handler('is_int'); + $handler = set_exception_handler('var_dump'); $this->earlyHandler = \is_array($handler) ? $handler[0] : null; restore_exception_handler(); @@ -84,7 +84,7 @@ public function configure(?object $event = null) $this->firstCall = $this->hasTerminatedWithException = false; $hasRun = null; - $handler = set_exception_handler('is_int'); + $handler = set_exception_handler('var_dump'); $handler = \is_array($handler) ? $handler[0] : null; restore_exception_handler(); diff --git a/src/Symfony/Component/Runtime/GenericRuntime.php b/src/Symfony/Component/Runtime/GenericRuntime.php index fa9364881363e..7c202c282e27e 100644 --- a/src/Symfony/Component/Runtime/GenericRuntime.php +++ b/src/Symfony/Component/Runtime/GenericRuntime.php @@ -71,15 +71,15 @@ public function __construct(array $options = []) if ($debug) { umask(0000); $_SERVER[$debugKey] = $_ENV[$debugKey] = '1'; - - if (false !== $errorHandler = ($options['error_handler'] ?? BasicErrorHandler::class)) { - $errorHandler::register($debug); - $options['error_handler'] = false; - } } else { $_SERVER[$debugKey] = $_ENV[$debugKey] = '0'; } + if (false !== $errorHandler = ($options['error_handler'] ?? BasicErrorHandler::class)) { + $errorHandler::register($debug); + $options['error_handler'] = false; + } + $this->options = $options; } diff --git a/src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php b/src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php index 6f41af585e616..d4e90a386c356 100644 --- a/src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php +++ b/src/Symfony/Component/Runtime/Internal/BasicErrorHandler.php @@ -30,10 +30,10 @@ public static function register(bool $debug): void } if (0 <= \ini_get('zend.assertions')) { - ini_set('zend.assertions', 1); - ini_set('assert.active', $debug); - ini_set('assert.exception', 1); + ini_set('zend.assertions', (int) $debug); } + ini_set('assert.active', 1); + ini_set('assert.exception', 1); set_error_handler(new self()); } diff --git a/src/Symfony/Component/Runtime/Internal/SymfonyErrorHandler.php b/src/Symfony/Component/Runtime/Internal/SymfonyErrorHandler.php index 40c125a91e333..0dfc7de0ca7a0 100644 --- a/src/Symfony/Component/Runtime/Internal/SymfonyErrorHandler.php +++ b/src/Symfony/Component/Runtime/Internal/SymfonyErrorHandler.php @@ -24,12 +24,31 @@ class SymfonyErrorHandler { public static function register(bool $debug): void { - BasicErrorHandler::register($debug); + if (!class_exists(ErrorHandler::class)) { + BasicErrorHandler::register($debug); - if (class_exists(ErrorHandler::class)) { + return; + } + + error_reporting(-1); + + if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { + ini_set('display_errors', $debug); + } elseif (!filter_var(\ini_get('log_errors'), \FILTER_VALIDATE_BOOL) || \ini_get('error_log')) { + // CLI - display errors only if they're not already logged to STDERR + ini_set('display_errors', 1); + } + + if (0 <= \ini_get('zend.assertions')) { + ini_set('zend.assertions', (int) $debug); + } + ini_set('assert.active', 1); + ini_set('assert.exception', 1); + + if ($debug) { DebugClassLoader::enable(); - restore_error_handler(); - ErrorHandler::register(new ErrorHandler(new BufferingLogger(), $debug)); } + + ErrorHandler::register(new ErrorHandler(new BufferingLogger(), $debug)); } }