Skip to content

Fix HTTP status code modification while exception handling (#2027) - #2028

Open
tanakahisateru wants to merge 1 commit into
Seldaek:mainfrom
tanakahisateru:fix-status-code-for-exception
Open

Fix HTTP status code modification while exception handling (#2027)#2028
tanakahisateru wants to merge 1 commit into
Seldaek:mainfrom
tanakahisateru:fix-status-code-for-exception

Conversation

@tanakahisateru

Copy link
Copy Markdown

Fixes #2027

The headers_sent() guard does not prevent the E_WARNING from http_response_code(). The warning is emitted when header('HTTP/...') has already been called, but headers_sent() only becomes true after output is flushed to the stream — these are independent states.

headers_list() might seem like an alternative to detect a previously set status line, but it intentionally excludes the HTTP status line.

Dropping the headers_sent() check and suppressing the warning with @ is the most correct approach available: it sets 500 when possible and silently does nothing when it cannot.

@Seldaek

Seldaek commented May 30, 2026

Copy link
Copy Markdown
Owner

I see the value of adding the @, but why remove the check? Sounds to me like it's still better to avoid creating an E_WARNING if we can (i.e. if headers are sent we know it is going to error so might as well skip it).

@Seldaek Seldaek added this to the 3.x milestone May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E_WARNING from http_response_code() in handleException when a status line has been registered via header() but not yet sent

2 participants