@@ -428,16 +428,12 @@ protected function initializeContainer()
428
428
$ cache = new ConfigCache ($ cacheDir .'/ ' .$ class .'.php ' , $ this ->debug );
429
429
$ cachePath = $ cache ->getPath ();
430
430
431
- // Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors
432
- $ errorLevel = error_reporting (E_ALL ^ E_WARNING );
433
-
434
431
try {
435
- if (file_exists ( $ cachePath ) && \is_object ($ this ->container = include $ cachePath )
432
+ if (\is_object ($ this ->container = $ this -> includeSafe ( $ cachePath) )
436
433
&& (!$ this ->debug || (self ::$ freshCache [$ cachePath ] ?? $ cache ->isFresh ()))
437
434
) {
438
435
self ::$ freshCache [$ cachePath ] = true ;
439
436
$ this ->container ->set ('kernel ' , $ this );
440
- error_reporting ($ errorLevel );
441
437
442
438
return ;
443
439
}
@@ -455,7 +451,7 @@ protected function initializeContainer()
455
451
if (!flock ($ lock , $ wouldBlock ? LOCK_SH : LOCK_EX )) {
456
452
fclose ($ lock );
457
453
$ lock = null ;
458
- } elseif (!\is_object ($ this ->container = include $ cachePath )) {
454
+ } elseif (!\is_object ($ this ->container = $ this -> includeSafe ( $ cachePath) )) {
459
455
$ this ->container = null ;
460
456
} elseif (!$ oldContainer || \get_class ($ this ->container ) !== $ oldContainer ->name ) {
461
457
flock ($ lock , LOCK_UN );
@@ -466,8 +462,6 @@ protected function initializeContainer()
466
462
}
467
463
}
468
464
} catch (\Throwable $ e ) {
469
- } finally {
470
- error_reporting ($ errorLevel );
471
465
}
472
466
473
467
if ($ collectDeprecations = $ this ->debug && !\defined ('PHPUNIT_COMPOSER_INSTALL ' )) {
@@ -789,6 +783,23 @@ public static function stripComments(string $source)
789
783
return $ output ;
790
784
}
791
785
786
+ /**
787
+ * Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors.
788
+ *
789
+ * @return mixed
790
+ */
791
+ private function includeSafe (string $ path )
792
+ {
793
+ $ errorLevel = error_reporting (E_ALL ^ E_WARNING );
794
+ try {
795
+ $ result = include $ path ;
796
+ } finally {
797
+ error_reporting ($ errorLevel );
798
+ }
799
+
800
+ return $ result ;
801
+ }
802
+
792
803
/**
793
804
* @return array
794
805
*/
0 commit comments