Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[HttpFoundation] Emit PHP warning whenResponse::sendHeaders() is called while output has already been sent#60377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedMay 7, 2025
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
nicolas-grekas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I doubt calling error_log is fine: we should use the logger infrastructure instead.
But Response is not a service, it doesn't fit.
Then, I'm wondering which service could be responsible for doing this check and logging the issue.
Maybe ErrorListener since it already has a logger injected? Any other idea?
Response::sendHeaders()nicolas-grekas commentedMay 9, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I guess that's a possiblity that would work: @ivo95v up to update your PR? |
ivo95v commentedMay 9, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
thank you@nicolas-grekas, sending header instead of error_log is a good idea. I just update the PR |
Response::sendHeaders()Response::sendHeaders()Response::sendHeaders()Response::sendHeaders() while output has already been sent…output has already been sent
6359c43 toa69cf15CompareResponse::sendHeaders() while output has already been sentResponse::sendHeaders() is called while output has already been sentfabpot commentedMay 10, 2025
Thank you@ivo95v. |
cf554e1 intosymfony:7.3Uh oh!
There was an error while loading.Please reload this page.
sarukomine commentedMay 31, 2025
Hi, I think this PR now affecting stream response, it will keep on triggering "Cannot modify header information" error such aslivewire/livewire#9357 |
OskarStark commentedMay 31, 2025
Can you please open a new issue to kept he conversation there? Thanks |
sarukomine commentedMay 31, 2025
Just opened#60603, thanks |
jase-languasco commentedMay 31, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
🤦 I'm also not able to upgrade to 7.3 because of this change. If I comment out the header function call my application works fine. There could be plenty of situations where headers have been sent on purpose at this point, so I would expect the early return of the object and not additional headers trying to be set forcing an error. Reading the initial issue, this seems extreme for an accident white space. That is not the only scenario in which headers have been sent at this point. I would instead recommend some static analysis on your project. |
instashop-dev commentedJun 20, 2025
@jase-languasco found any workaround for this issue ? |
jase-languasco commentedJun 20, 2025
@instashop-dev I'm forced to specify the version before in composer.json. I won't be able to upgrade to this version. |
…:sendHeaders()` is called while output has already been sent" (nicolas-grekas)This PR was merged into the 7.3 branch.Discussion----------[HttpFoundation] Revert " Emit PHP warning when `Response::sendHeaders()` is called while output has already been sent"| Q | A| ------------- | ---| Branch? | 7.3| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues |Fix#60603| License | MITThis reverts commitcf554e1, reversing changes made to392d0c9.Let's revert as this change is too disruptive for a minor version (and I'm also going to replace this by a deprecation on 7.4 so that we can throw the warning in 8.0)Commits-------51985c9 Revert "minor#60377 [HttpFoundation] Emit PHP warning when `Response::sendHeaders()` is called while output has already been sent (ivo95v)"
* 7.3: Revert "minor#60377 [HttpFoundation] Emit PHP warning when `Response::sendHeaders()` is called while output has already been sent (ivo95v)" [Validator] Add missing HasNamedArguments to some constraints
nicolas-grekas commentedJun 23, 2025
* 7.4: [HttpFoundation] Deprecate using `Request::sendHeaders()` after headers have already been sent Revert "minor#60377 [HttpFoundation] Emit PHP warning when `Response::sendHeaders()` is called while output has already been sent (ivo95v)" [Validator] Add missing HasNamedArguments to some constraints [Serializer] Remove unused variable Add support for Invokable Commands in CommandTester
Uh oh!
There was an error while loading.Please reload this page.
Description:
When Symfony attempts to send HTTP headers via the sendHeaders() method, it silently aborts if headers have already been sent (e.g., due to whitespace before the <?php tag). I spent an entire day debugging this issue and discovered that the problem was caused by an unintended whitespace before a PHP opening tag. To avoid this kind of silent failure and make future debugging easier, I decided to add an error log.