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.
This commit is contained in:
Jerome TAMARELLE 2014-03-24 15:16:05 +01:00 committed by Fabien Potencier
parent 26d4db3e8b
commit 97591c1b30

View File

@ -91,9 +91,11 @@ class ExceptionHandler
$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));