From a7aaa931315d35e4a04b7403277586b22162365a Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 8 Jan 2015 21:47:13 -0500 Subject: [PATCH 1/2] Convert header_sent exception into a notice error. Throwing an exception here, causes an infinite loop when handling fatal errors, as the shutdown function sends headers automatically. Refs #5595 --- lib/Cake/Network/CakeResponse.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index d5e10c657..e610bf2f7 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -520,9 +520,11 @@ class CakeResponse { */ protected function _sendHeader($name, $value = null) { if (headers_sent($filename, $linenum)) { - throw new CakeException( - __d('cake_dev', 'Headers already sent in %s on line %s', $filename, $linenum) + trigger_error( + __d('cake_dev', 'Headers already sent in %s on line %s', $filename, $linenum), + E_USER_NOTICE ); + return; } if ($value === null) { header($name); From 18f02bf5b33f5bce78008d3c2d0860cc25b17bf0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 9 Jan 2015 15:16:14 -0500 Subject: [PATCH 2/2] Don't emit errors or trigger exceptions when headers have been sent. After discussing it a bit, we've come to consensus that emitting errors or throwing exceptions are both pretty disruptive and annoying to deal with. Instead we'll revert to the previous 2.x behavior of doing nothing. --- lib/Cake/Network/CakeResponse.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index e610bf2f7..9902fe632 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -513,17 +513,14 @@ class CakeResponse { /** * Sends a header to the client. * + * Will skip sending headers if headers have already been sent. + * * @param string $name the header name * @param string $value the header value * @return void - * @throws CakeException When headers have already been sent */ protected function _sendHeader($name, $value = null) { if (headers_sent($filename, $linenum)) { - trigger_error( - __d('cake_dev', 'Headers already sent in %s on line %s', $filename, $linenum), - E_USER_NOTICE - ); return; } if ($value === null) {