diff --git a/UPGRADE-7.4.md b/UPGRADE-7.4.md index 487bf6f5007a6..859fd57d0afa6 100644 --- a/UPGRADE-7.4.md +++ b/UPGRADE-7.4.md @@ -22,3 +22,8 @@ HttpClient ---------- * Deprecate using amphp/http-client < 5 + +HttpFoundation +-------------- + + * Deprecate using `Request::sendHeaders()` after headers have already been sent; use a `StreamedResponse` instead diff --git a/src/Symfony/Component/HttpFoundation/CHANGELOG.md b/src/Symfony/Component/HttpFoundation/CHANGELOG.md index 374c31889df3c..ca58a4032d8b8 100644 --- a/src/Symfony/Component/HttpFoundation/CHANGELOG.md +++ b/src/Symfony/Component/HttpFoundation/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Deprecate using `Request::sendHeaders()` after headers have already been sent; use a `StreamedResponse` instead + 7.3 --- diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 455b026dffb05..173ee3f93eb3b 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -319,7 +319,8 @@ public function sendHeaders(?int $statusCode = null): static if (headers_sent()) { if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { $statusCode ??= $this->statusCode; - header(\sprintf('HTTP/%s %s %s', $this->version, $statusCode, $this->statusText), true, $statusCode); + trigger_deprecation('symfony/http-foundation', '7.4', 'Trying to use "%s::sendHeaders()" after headers have already been sent is deprecated will throw a PHP warning in 8.0. Use a "StreamedResponse" instead.', static::class); + //header(\sprintf('HTTP/%s %s %s', $this->version, $statusCode, $this->statusText), true, $statusCode); } return $this;