Skip to content

Commit aad56a6

Browse files
committed
Fix #74 - Support missing function error_reporting
1 parent 8103e6c commit aad56a6

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Console/Application.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@
2121
use Doctum\Doctum;
2222
use Symfony\Component\Console\Application as BaseApplication;
2323

24+
use function function_exists;
25+
use function error_reporting;
26+
2427
class Application extends BaseApplication
2528
{
2629

2730
public function __construct()
2831
{
29-
error_reporting(-1);
32+
if (function_exists('error_reporting')) {
33+
error_reporting(-1);
34+
}
3035
ErrorHandler::register();
3136

3237
parent::__construct('Doctum', Doctum::VERSION);

src/ErrorHandler.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313

1414
namespace Doctum;
1515

16+
use function function_exists;
17+
use function error_reporting;
18+
use function sprintf;
19+
use function set_error_handler;
20+
21+
use const E_ALL;
22+
use const E_ERROR;
23+
use const E_WARNING;
24+
use const E_NOTICE;
25+
use const E_USER_ERROR;
26+
use const E_USER_WARNING;
27+
use const E_USER_NOTICE;
28+
use const E_USER_DEPRECATED;
29+
use const E_RECOVERABLE_ERROR;
30+
1631
final class ErrorHandler
1732
{
1833
private const ERROR_LEVELS = [
@@ -39,11 +54,18 @@ public static function register(): void
3954
*/
4055
public function handle($level, $message, $file = 'unknown', $line = 0, $context = []): bool
4156
{
57+
$currentLevel = E_ALL;
58+
59+
if (function_exists('error_reporting')) {
60+
$currentLevel = error_reporting();
61+
}
62+
4263
/**
4364
* Check if Error Control Operator (@) was used
4465
* See: https://php.watch/versions/8.0/fatal-error-suppression#suppress-error-handlers
4566
*/
46-
$isSilenced = ! (error_reporting() & $level);
67+
$isSilenced = ! ($currentLevel & $level);
68+
4769

4870
if (! $isSilenced) {
4971
throw new \ErrorException(sprintf('%s: %s in %s line %d', self::ERROR_LEVELS[$level] ?? $level, $message, $file, $line));

0 commit comments

Comments
 (0)