Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 6.4:
  Tweak error/exception handler registration
  • Loading branch information
nicolas-grekas committed Sep 25, 2024
2 parents 76be495 + 7fa1bc6 commit 51477fd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
10 changes: 5 additions & 5 deletions GenericRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions Internal/BasicErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
27 changes: 23 additions & 4 deletions Internal/SymfonyErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 51477fd

Please sign in to comment.