From a69cf15e51cd1e42b5a34d448cc053a772ad05f5 Mon Sep 17 00:00:00 2001 From: ivelin vasilev Date: Thu, 8 May 2025 01:06:34 +0300 Subject: [PATCH] [HttpFoundation] Emit PHP warning when Response::sendHeaders() while output has already been sent --- src/Symfony/Component/HttpFoundation/Response.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 638b5bf601347..6766f2c77099e 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -317,6 +317,11 @@ public function sendHeaders(?int $statusCode = null): static { // headers have already been sent by the developer 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); + } + return $this; }