49
49
class ErrorHandler
50
50
{
51
51
private $ levels = [
52
- E_DEPRECATED => 'Deprecated ' ,
53
- E_USER_DEPRECATED => 'User Deprecated ' ,
54
- E_NOTICE => 'Notice ' ,
55
- E_USER_NOTICE => 'User Notice ' ,
56
- E_STRICT => 'Runtime Notice ' ,
57
- E_WARNING => 'Warning ' ,
58
- E_USER_WARNING => 'User Warning ' ,
59
- E_COMPILE_WARNING => 'Compile Warning ' ,
60
- E_CORE_WARNING => 'Core Warning ' ,
61
- E_USER_ERROR => 'User Error ' ,
62
- E_RECOVERABLE_ERROR => 'Catchable Fatal Error ' ,
63
- E_COMPILE_ERROR => 'Compile Error ' ,
64
- E_PARSE => 'Parse Error ' ,
65
- E_ERROR => 'Error ' ,
66
- E_CORE_ERROR => 'Core Error ' ,
52
+ \ E_DEPRECATED => 'Deprecated ' ,
53
+ \ E_USER_DEPRECATED => 'User Deprecated ' ,
54
+ \ E_NOTICE => 'Notice ' ,
55
+ \ E_USER_NOTICE => 'User Notice ' ,
56
+ \ E_STRICT => 'Runtime Notice ' ,
57
+ \ E_WARNING => 'Warning ' ,
58
+ \ E_USER_WARNING => 'User Warning ' ,
59
+ \ E_COMPILE_WARNING => 'Compile Warning ' ,
60
+ \ E_CORE_WARNING => 'Core Warning ' ,
61
+ \ E_USER_ERROR => 'User Error ' ,
62
+ \ E_RECOVERABLE_ERROR => 'Catchable Fatal Error ' ,
63
+ \ E_COMPILE_ERROR => 'Compile Error ' ,
64
+ \ E_PARSE => 'Parse Error ' ,
65
+ \ E_ERROR => 'Error ' ,
66
+ \ E_CORE_ERROR => 'Core Error ' ,
67
67
];
68
68
69
69
private $ loggers = [
70
- E_DEPRECATED => [null , LogLevel::INFO ],
71
- E_USER_DEPRECATED => [null , LogLevel::INFO ],
72
- E_NOTICE => [null , LogLevel::WARNING ],
73
- E_USER_NOTICE => [null , LogLevel::WARNING ],
74
- E_STRICT => [null , LogLevel::WARNING ],
75
- E_WARNING => [null , LogLevel::WARNING ],
76
- E_USER_WARNING => [null , LogLevel::WARNING ],
77
- E_COMPILE_WARNING => [null , LogLevel::WARNING ],
78
- E_CORE_WARNING => [null , LogLevel::WARNING ],
79
- E_USER_ERROR => [null , LogLevel::CRITICAL ],
80
- E_RECOVERABLE_ERROR => [null , LogLevel::CRITICAL ],
81
- E_COMPILE_ERROR => [null , LogLevel::CRITICAL ],
82
- E_PARSE => [null , LogLevel::CRITICAL ],
83
- E_ERROR => [null , LogLevel::CRITICAL ],
84
- E_CORE_ERROR => [null , LogLevel::CRITICAL ],
70
+ \ E_DEPRECATED => [null , LogLevel::INFO ],
71
+ \ E_USER_DEPRECATED => [null , LogLevel::INFO ],
72
+ \ E_NOTICE => [null , LogLevel::WARNING ],
73
+ \ E_USER_NOTICE => [null , LogLevel::WARNING ],
74
+ \ E_STRICT => [null , LogLevel::WARNING ],
75
+ \ E_WARNING => [null , LogLevel::WARNING ],
76
+ \ E_USER_WARNING => [null , LogLevel::WARNING ],
77
+ \ E_COMPILE_WARNING => [null , LogLevel::WARNING ],
78
+ \ E_CORE_WARNING => [null , LogLevel::WARNING ],
79
+ \ E_USER_ERROR => [null , LogLevel::CRITICAL ],
80
+ \ E_RECOVERABLE_ERROR => [null , LogLevel::CRITICAL ],
81
+ \ E_COMPILE_ERROR => [null , LogLevel::CRITICAL ],
82
+ \ E_PARSE => [null , LogLevel::CRITICAL ],
83
+ \ E_ERROR => [null , LogLevel::CRITICAL ],
84
+ \ E_CORE_ERROR => [null , LogLevel::CRITICAL ],
85
85
];
86
86
87
87
private $ thrownErrors = 0x1FFF ; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED
@@ -154,7 +154,7 @@ public static function register(self $handler = null, $replace = true)
154
154
$ handler ->setExceptionHandler ($ prev );
155
155
}
156
156
157
- $ handler ->throwAt (E_ALL & $ handler ->thrownErrors , true );
157
+ $ handler ->throwAt (\ E_ALL & $ handler ->thrownErrors , true );
158
158
159
159
return $ handler ;
160
160
}
@@ -176,7 +176,7 @@ public function __construct(BufferingLogger $bootstrappingLogger = null)
176
176
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
177
177
* @param bool $replace Whether to replace or not any existing logger
178
178
*/
179
- public function setDefaultLogger (LoggerInterface $ logger , $ levels = E_ALL , $ replace = false )
179
+ public function setDefaultLogger (LoggerInterface $ logger , $ levels = \ E_ALL , $ replace = false )
180
180
{
181
181
$ loggers = [];
182
182
@@ -188,7 +188,7 @@ public function setDefaultLogger(LoggerInterface $logger, $levels = E_ALL, $repl
188
188
}
189
189
} else {
190
190
if (null === $ levels ) {
191
- $ levels = E_ALL ;
191
+ $ levels = \ E_ALL ;
192
192
}
193
193
foreach ($ this ->loggers as $ type => $ log ) {
194
194
if (($ type & $ levels ) && (empty ($ log [0 ]) || $ replace || $ log [0 ] === $ this ->bootstrappingLogger )) {
@@ -242,7 +242,7 @@ public function setLoggers(array $loggers)
242
242
243
243
if ($ flush ) {
244
244
foreach ($ this ->bootstrappingLogger ->cleanLogs () as $ log ) {
245
- $ type = $ log [2 ]['exception ' ] instanceof \ErrorException ? $ log [2 ]['exception ' ]->getSeverity () : E_ERROR ;
245
+ $ type = $ log [2 ]['exception ' ] instanceof \ErrorException ? $ log [2 ]['exception ' ]->getSeverity () : \ E_ERROR ;
246
246
if (!isset ($ flush [$ type ])) {
247
247
$ this ->bootstrappingLogger ->log ($ log [0 ], $ log [1 ], $ log [2 ]);
248
248
} elseif ($ this ->loggers [$ type ][0 ]) {
@@ -280,7 +280,7 @@ public function setExceptionHandler(callable $handler = null)
280
280
public function throwAt ($ levels , $ replace = false )
281
281
{
282
282
$ prev = $ this ->thrownErrors ;
283
- $ this ->thrownErrors = ($ levels | E_RECOVERABLE_ERROR | E_USER_ERROR ) & ~E_USER_DEPRECATED & ~E_DEPRECATED ;
283
+ $ this ->thrownErrors = ($ levels | \ E_RECOVERABLE_ERROR | \ E_USER_ERROR ) & ~\ E_USER_DEPRECATED & ~\ E_DEPRECATED ;
284
284
if (!$ replace ) {
285
285
$ this ->thrownErrors |= $ prev ;
286
286
}
@@ -382,15 +382,15 @@ private function reRegister($prev)
382
382
*/
383
383
public function handleError ($ type , $ message , $ file , $ line )
384
384
{
385
- if (\PHP_VERSION_ID >= 70300 && E_WARNING === $ type && '" ' === $ message [0 ] && false !== strpos ($ message , '" targeting switch is equivalent to "break ' )) {
386
- $ type = E_DEPRECATED ;
385
+ if (\PHP_VERSION_ID >= 70300 && \ E_WARNING === $ type && '" ' === $ message [0 ] && false !== strpos ($ message , '" targeting switch is equivalent to "break ' )) {
386
+ $ type = \ E_DEPRECATED ;
387
387
}
388
388
389
389
// Level is the current error reporting level to manage silent error.
390
390
$ level = error_reporting ();
391
391
$ silenced = 0 === ($ level & $ type );
392
392
// Strong errors are not authorized to be silenced.
393
- $ level |= E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED ;
393
+ $ level |= \ E_RECOVERABLE_ERROR | \ E_USER_ERROR | \ E_DEPRECATED | \ E_USER_DEPRECATED ;
394
394
$ log = $ this ->loggedErrors & $ type ;
395
395
$ throw = $ this ->thrownErrors & $ type & $ level ;
396
396
$ type &= $ level | $ this ->screamedErrors ;
@@ -414,7 +414,7 @@ public function handleError($type, $message, $file, $line)
414
414
$ context = $ e ;
415
415
}
416
416
417
- if (null !== $ backtrace && $ type & E_ERROR ) {
417
+ if (null !== $ backtrace && $ type & \ E_ERROR ) {
418
418
// E_ERROR fatal errors are triggered on HHVM when
419
419
// hhvm.error_handling.call_user_handler_on_fatals=1
420
420
// which is the way to get their backtrace.
@@ -430,7 +430,7 @@ public function handleError($type, $message, $file, $line)
430
430
self ::$ toStringException = null ;
431
431
} elseif (!$ throw && !($ type & $ level )) {
432
432
if (!isset (self ::$ silencedErrorCache [$ id = $ file .': ' .$ line ])) {
433
- $ lightTrace = $ this ->tracedErrors & $ type ? $ this ->cleanTrace (debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 3 ), $ type , $ file , $ line , false ) : [];
433
+ $ lightTrace = $ this ->tracedErrors & $ type ? $ this ->cleanTrace (debug_backtrace (\ DEBUG_BACKTRACE_IGNORE_ARGS , 3 ), $ type , $ file , $ line , false ) : [];
434
434
$ errorAsException = new SilencedErrorContext ($ type , $ file , $ line , $ lightTrace );
435
435
} elseif (isset (self ::$ silencedErrorCache [$ id ][$ message ])) {
436
436
$ lightTrace = null ;
@@ -469,7 +469,7 @@ public function handleError($type, $message, $file, $line)
469
469
}
470
470
471
471
if ($ throw ) {
472
- if (\PHP_VERSION_ID < 70400 && E_USER_ERROR & $ type ) {
472
+ if (\PHP_VERSION_ID < 70400 && \ E_USER_ERROR & $ type ) {
473
473
for ($ i = 1 ; isset ($ backtrace [$ i ]); ++$ i ) {
474
474
if (isset ($ backtrace [$ i ]['function ' ], $ backtrace [$ i ]['type ' ], $ backtrace [$ i - 1 ]['function ' ])
475
475
&& '__toString ' === $ backtrace [$ i ]['function ' ]
@@ -558,7 +558,7 @@ public function handleException($exception, array $error = null)
558
558
if (!$ exception instanceof \Exception) {
559
559
$ exception = new FatalThrowableError ($ exception );
560
560
}
561
- $ type = $ exception instanceof FatalErrorException ? $ exception ->getSeverity () : E_ERROR ;
561
+ $ type = $ exception instanceof FatalErrorException ? $ exception ->getSeverity () : \ E_ERROR ;
562
562
$ handlerException = null ;
563
563
564
564
if (($ this ->loggedErrors & $ type ) || $ exception instanceof FatalThrowableError) {
@@ -674,7 +674,7 @@ public static function handleFatalError(array $error = null)
674
674
// Handled below
675
675
}
676
676
677
- if ($ error && $ error ['type ' ] &= E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR ) {
677
+ if ($ error && $ error ['type ' ] &= \ E_PARSE | \ E_ERROR | \ E_CORE_ERROR | \ E_COMPILE_ERROR ) {
678
678
// Let's not throw anymore but keep logging
679
679
$ handler ->throwAt (0 , true );
680
680
$ trace = isset ($ error ['backtrace ' ]) ? $ error ['backtrace ' ] : null ;
@@ -716,9 +716,9 @@ public static function handleFatalError(array $error = null)
716
716
*/
717
717
public static function stackErrors ()
718
718
{
719
- @trigger_error ('Support for stacking errors is deprecated since Symfony 3.4 and will be removed in 4.0. ' , E_USER_DEPRECATED );
719
+ @trigger_error ('Support for stacking errors is deprecated since Symfony 3.4 and will be removed in 4.0. ' , \ E_USER_DEPRECATED );
720
720
721
- self ::$ stackedErrorLevels [] = error_reporting (error_reporting () | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR );
721
+ self ::$ stackedErrorLevels [] = error_reporting (error_reporting () | \ E_PARSE | \ E_ERROR | \ E_CORE_ERROR | \ E_COMPILE_ERROR );
722
722
}
723
723
724
724
/**
@@ -728,13 +728,13 @@ public static function stackErrors()
728
728
*/
729
729
public static function unstackErrors ()
730
730
{
731
- @trigger_error ('Support for unstacking errors is deprecated since Symfony 3.4 and will be removed in 4.0. ' , E_USER_DEPRECATED );
731
+ @trigger_error ('Support for unstacking errors is deprecated since Symfony 3.4 and will be removed in 4.0. ' , \ E_USER_DEPRECATED );
732
732
733
733
$ level = array_pop (self ::$ stackedErrorLevels );
734
734
735
735
if (null !== $ level ) {
736
736
$ errorReportingLevel = error_reporting ($ level );
737
- if ($ errorReportingLevel !== ($ level | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR )) {
737
+ if ($ errorReportingLevel !== ($ level | \ E_PARSE | \ E_ERROR | \ E_CORE_ERROR | \ E_COMPILE_ERROR )) {
738
738
// If the user changed the error level, do not overwrite it
739
739
error_reporting ($ errorReportingLevel );
740
740
}
0 commit comments