Skip to content

Commit 51477fd

Browse files
Merge branch '6.4' into 7.1
* 6.4: Tweak error/exception handler registration
2 parents 76be495 + 7fa1bc6 commit 51477fd

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

GenericRuntime.php

+5-5
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

Internal/BasicErrorHandler.php

+3-3
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
}

Internal/SymfonyErrorHandler.php

+23-4
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)