File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ final class ErrorHandler
45
45
*/
46
46
private $ logVariables = true ;
47
47
48
+ /**
49
+ * @var null|bool
50
+ */
51
+ private $ displayErrors ;
52
+
48
53
/**
49
54
* @var callable
50
55
*/
@@ -186,6 +191,21 @@ public function logVariables(): bool
186
191
return $ this ->logVariables ;
187
192
}
188
193
194
+ public function setDisplayErrors (bool $ displayErrors ): void
195
+ {
196
+ $ this ->displayErrors = $ displayErrors ;
197
+ }
198
+
199
+ public function displayErrors (): bool
200
+ {
201
+ if (null === $ this ->displayErrors ) {
202
+ $ this ->setDisplayErrors ((bool ) \ini_get ('display_errors ' ));
203
+ \assert (null !== $ this ->displayErrors );
204
+ }
205
+
206
+ return $ this ->displayErrors ;
207
+ }
208
+
189
209
/**
190
210
* @param array<int, bool> $scream
191
211
*/
@@ -287,7 +307,7 @@ public function exceptionHandler(Throwable $exception): void
287
307
}
288
308
$ output .= '<h1>500: Errore interno</h1> ' ;
289
309
$ output .= \PHP_EOL ;
290
- if (true === ( bool ) \ini_get ( ' display_errors ' )) {
310
+ if ($ this -> displayErrors ( )) {
291
311
$ currentEx = $ exception ;
292
312
do {
293
313
$ output .= \sprintf (
Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ final class ErrorHandlerTest extends TestCase
38
38
39
39
protected function setUp (): void
40
40
{
41
- \ini_set ('display_errors ' , (string ) false );
42
41
$ this ->backupErrorLog = (string ) \ini_get ('error_log ' );
43
42
$ this ->errorLog = __DIR__ . \DIRECTORY_SEPARATOR . 'error_log_test ' ;
44
43
\touch ($ this ->errorLog );
@@ -145,7 +144,7 @@ public function testHandleCliException(): void
145
144
146
145
public function testHandleWebExceptionWithDisplay (): void
147
146
{
148
- \ini_set ( ' display_errors ' , ( string ) true );
147
+ $ this -> errorHandler -> setDisplayErrors ( true );
149
148
$ this ->errorHandler ->setCli (false );
150
149
$ this ->errorHandler ->setLogErrors (true );
151
150
@@ -161,7 +160,7 @@ public function testHandleWebExceptionWithDisplay(): void
161
160
162
161
public function testHandleWebExceptionWithoutDisplay (): void
163
162
{
164
- \ini_set ( ' display_errors ' , ( string ) false );
163
+ $ this -> errorHandler -> setDisplayErrors ( false );
165
164
$ this ->errorHandler ->setCli (false );
166
165
$ this ->errorHandler ->setLogErrors (true );
167
166
You can’t perform that action at this time.
0 commit comments