8000 Check headers sent before sending PHP response · webmozart/symfony@97591c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 97591c1

Browse files
GromNaNfabpot
authored andcommitted
Check headers sent before sending PHP response
If the response contents has been sent before an error occurs, PHP triggers the warning "Cannot modify header information - headers already sent" This change ensure that the error message is echoed, while it's impossible to change the HTTP status code and headers.
1 parent 26d4db3 commit 97591c1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ public function sendPhpResponse($exception)
9191
$exception = FlattenException::create($exception);
9292
}
9393

94-
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
95-
foreach ($exception->getHeaders() as $name => $value) {
96-
header($name.': '.$value, false);
94+
if (!headers_sent()) {
95+
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
96+
foreach ($exception->getHeaders() as $name => $value) {
97+
header($name.': '.$value, false);
98+
}
9799
}
98100

99101
echo $this->decorate($this->getContent($exception), $this->getStylesheet($exception));

0 commit comments

Comments
 (0)
0