Skip to content

Commit

Permalink
[HttpFoundation] prevented Response headers to be sent twice
Browse files Browse the repository at this point in the history
This change allows for more flexibility if the developer wants to flush
the Response content early (the drawback being that Response listeners
won't be able to tweak the HTTP headers anymore).

There is another benefit: avoid the infamous
"Fatal error: Exception thrown without a stack frame in Unknown on line 0".

Here is a small scenario when this can happen (thanks dtee for identifying this issue):

* Call flush() in controller to output html early, then throw exception
* ExceptionHandler triggers handle() function and return new Response object to output...
* Because the header is sent (flush() call in Controller), php's E_WARNING error get raised, which gets handled by ErrorHandler->handle() and it throws new ErrorException()
* PHP fatals to prevent Exception loop: "Fatal error: Exception thrown without a stack frame in Unknown on line 0"
  • Loading branch information
fabpot committed Jul 7, 2011
1 parent 6645cb4 commit bb5075d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -119,6 +119,11 @@ public function __clone()
*/
public function sendHeaders()
{
// headers have already been sent by the developer
if (headers_sent()) {
return;
}

$this->fixContentType();

// status
Expand Down

0 comments on commit bb5075d

Please sign in to comment.