-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Warn on http_response_code() after header('HTTP/...') #18962
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+48
−0
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--TEST-- | ||
GH-18582: Allow http_response_code() to clear HTTP start-line | ||
--SKIPIF-- | ||
<?php | ||
include "skipif.inc"; | ||
?> | ||
--FILE-- | ||
<?php | ||
include "php_cli_server.inc"; | ||
|
||
php_cli_server_start(<<<'PHP' | ||
http_response_code(401); | ||
header('HTTP/1.1 404 Not Found'); | ||
$is_404 = http_response_code(403); | ||
$should_be_404_but_is_403 = http_response_code(); | ||
echo $is_404 . PHP_EOL; | ||
echo $should_be_404_but_is_403 . PHP_EOL; | ||
PHP); | ||
|
||
$host = PHP_CLI_SERVER_HOSTNAME; | ||
$fp = php_cli_server_connect(); | ||
if (fwrite($fp, "GET / HTTP/1.1\nHost: {$host}\n\n")) { | ||
while (!feof($fp)) { | ||
echo fgets($fp); | ||
} | ||
} | ||
fclose($fp); | ||
?> | ||
--EXPECTF-- | ||
HTTP/1.1 404 Not Found | ||
Host: %s | ||
Date: %s | ||
Connection: close | ||
X-Powered-By: %s | ||
Content-type: text/html; charset=UTF-8 | ||
|
||
<br /> | ||
<b>Warning</b>: http_response_code(): Calling http_response_code() after header('HTTP/...') has no effect. This will change in PHP 9.0 in <b>%s</b> on line <b>3</b><br /> | ||
404 | ||
403 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
That should be deprecation if it should change in 9.0 and it would also require RFC because the upcoming BC break. I think I would just add NOTICE for now and then leave it to anyone who want to do the RFC...
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.
Your stance on this issue is seriously baffling to me. Almost every bug fix has some risk of breakage. That's why we delay more risky fixes to master, including myself in this case. If that's not enough, delaying to the next major with a migration path should certainly be enough. I even offered a mailing list discussion. But if the fixing of obvious issues now requires RFCs, I don't know how we can get anything done. This is not only wasteful to the RFC author, but everyone who has to read it.
I made this a warning because such code is almost guaranteed to be misbehaving, rather than this being a feature that is being removed.