8000 bug #10523 [Debug] Check headers sent before sending PHP response (Gr… · h4ck3rm1k3/symfony@58f5f4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 58f5f4a

Browse files
committed
bug symfony#10523 [Debug] Check headers sent before sending PHP response (GromNaN)
This PR was merged into the 2.3 branch. Discussion ---------- [Debug] 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 useful error message is echoed, while it's impossible to change the HTTP status code and headers. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 97591c1 Check headers sent before sending PHP response
2 parents 26d4db3 + 97591c1 commit 58f5f4a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ public function sendPhpResponse($exception)
9191
$exception = FlattenException::create($exception);
9292
}
9393

94-
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
95-
foreach ($exception->getHeaders() as $name => $value) {
96-
header($name.': '.$value, false);
94+
if (!headers_sent()) {
95+
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
96+
foreach ($exception->getHeaders() as $name => $value) {
97+
header($name.': '.$value, false);
98+
}
9799
}
98100

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

0 commit comments

Comments
 (0)
0