From 97591c1b309cc6dcec9f00606530120054550f15 Mon Sep 17 00:00:00 2001 From: Jerome TAMARELLE Date: Mon, 24 Mar 2014 15:16:05 +0100 Subject: [PATCH] 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. --- src/Symfony/Component/Debug/ExceptionHandler.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index cd781b5609..458d647f0b 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -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));