Skip to content

Commit

Permalink
Check headers sent before sending PHP response
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GromNaN authored and fabpot committed Mar 26, 2014
1 parent 26d4db3 commit 97591c1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Symfony/Component/Debug/ExceptionHandler.php
Expand Up @@ -91,9 +91,11 @@ public function sendPhpResponse($exception)
$exception = FlattenException::create($exception);
}

header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
foreach ($exception->getHeaders() as $name => $value) {
header($name.': '.$value, false);
if (!headers_sent()) {
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
foreach ($exception->getHeaders() as $name => $value) {
header($name.': '.$value, false);
}
}

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

0 comments on commit 97591c1

Please sign in to comment.