Skip to content

http_response_code must emit a warning if headers were already flushed #10742

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
mvorisek opened this issue Mar 1, 2023 · 0 comments
Closed

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Mar 1, 2023

Description

The following code:

<?php

echo 'x';
ob_end_flush();
flush();
// header('test: test');
http_response_code(301);

Resulted in this output:

x

But I expected this output instead:

x
Warning:  Cannot modify response code - headers already sent by (output started at ....php:12) in ...

I would expect about the same warning as header() emit. In the repro above, I have verified header(string) emits a warning, but http_response_code(number) currently does not.

PHP Version

any

Operating System

any

NattyNarwhal added a commit to NattyNarwhal/php-src that referenced this issue Mar 1, 2023
This would fail silently otherwise. The warning should be similar to
the one that header emits (the code is some copy and paste from
main/SAPI.c, to match). It'll also return false in that case.

Fixes phpGH-10742
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant