Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:7.3fromivo95v:fix-missing-error-log
May 10, 2025

Conversation

@ivo95v
Copy link
Contributor

@ivo95vivo95v commentedMay 7, 2025
edited by nicolas-grekas
Loading

QA
Branch?7.3
Bug fix?no
New feature?no
Deprecations?no
Issues-
LicenseMIT

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.

@carsonbotcarsonbot added this to the7.3 milestoneMay 7, 2025
@carsonbot
Copy link

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:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.3 branch.

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!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@ivo95vivo95v changed the titleadded error log to symfony Response sendHeaders[HttpFoundation][Response]added error log to symfony Response sendHeadersMay 7, 2025
@ivo95vivo95v changed the title[HttpFoundation][Response]added error log to symfony Response sendHeaders[HttpFoundation][Response] added error log to symfony Response sendHeadersMay 7, 2025
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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?

@OskarStarkOskarStark changed the title[HttpFoundation][Response] added error log to symfony Response sendHeaders[HttpFoundation][Response] added error log toResponse::sendHeaders()May 9, 2025
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedMay 9, 2025
edited
Loading

I guess that's a possiblity that would work:
instead of the added line, we'd just do
header(\sprintf('HTTP/%s %s %s', $this->version, $statusCode, $this->statusText), true, $statusCode); and let PHP generate the proper warning.

@ivo95v up to update your PR?
Please mind the code style, indentation is broken at the moment.

ivo95v reacted with thumbs up emoji

@ivo95v
Copy link
ContributorAuthor

ivo95v commentedMay 9, 2025
edited
Loading

thank you@nicolas-grekas, sending header instead of error_log is a good idea. I just update the PR

@carsonbotcarsonbot changed the title[HttpFoundation][Response] added error log toResponse::sendHeaders()[HttpFoundation] [Response] added error log toResponse::sendHeaders()May 10, 2025
@nicolas-grekasnicolas-grekas changed the title[HttpFoundation] [Response] added error log toResponse::sendHeaders()[HttpFoundation] Emit PHP warning whenResponse::sendHeaders() while output has already been sentMay 10, 2025
@nicolas-grekasnicolas-grekas changed the title[HttpFoundation] Emit PHP warning whenResponse::sendHeaders() while output has already been sent[HttpFoundation] Emit PHP warning whenResponse::sendHeaders() is called while output has already been sentMay 10, 2025
@fabpot
Copy link
Member

Thank you@ivo95v.

ivo95v reacted with heart emoji

@fabpotfabpot merged commitcf554e1 intosymfony:7.3May 10, 2025
11 checks passed
@sarukomine
Copy link

Hi, I think this PR now affecting stream response, it will keep on triggering "Cannot modify header information" error such aslivewire/livewire#9357

clementmas reacted with thumbs up emoji

@OskarStark
Copy link
Contributor

Can you please open a new issue to kept he conversation there? Thanks

@sarukomine
Copy link

Can you please open a new issue to kept he conversation there? Thanks

Just opened#60603, thanks

OskarStark and gabrielrbarbosa reacted with rocket emoji

@jase-languasco
Copy link

jase-languasco commentedMay 31, 2025
edited
Loading

🤦 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.

gabrielrbarbosa reacted with thumbs up emoji

@instashop-dev
Copy link

@jase-languasco found any workaround for this issue ?

@jase-languasco
Copy link

@instashop-dev I'm forced to specify the version before in composer.json. I won't be able to upgrade to this version.

nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull requestJun 23, 2025
…esponse::sendHeaders()` is called while output has already been sent (ivo95v)"This reverts commitcf554e1, reversingchanges made to392d0c9.
nicolas-grekas added a commit that referenced this pull requestJun 23, 2025
…: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)"
nicolas-grekas added a commit that referenced this pull requestJun 23, 2025
* 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
Copy link
Member

The change has been reverted in#60875 but will be reintroduced in Symfony 8.0 after#60876 which is deprecating the behavior.

jase-languasco and sarukomine reacted with hooray emojijase-languasco and sarukomine reacted with heart emojijase-languasco and sarukomine reacted with rocket emoji

nicolas-grekas added a commit that referenced this pull requestJun 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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

7.3

Development

Successfully merging this pull request may close these issues.

8 participants

@ivo95v@carsonbot@nicolas-grekas@fabpot@sarukomine@OskarStark@jase-languasco@instashop-dev

[8]ページ先頭

©2009-2025 Movatter.jp