Skip to content

Document the compile-time and runtime checks for never - #5906

Merged
lacatoire merged 2 commits into
php:masterfrom
Cayan:never-compile-time-return-and-type-error
Oct 5, 2026
Merged

lacatoire merged 2 commits into
php:masterfrom
Cayan:never-compile-time-return-and-type-error

Conversation

@Cayan

@Cayan Cayan commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Closes #5390 (the two points that were missing; the exception and return-only parts are already on the page).

Adds the two sentences suggested in the issue: a return in a never function is a compile-time error even when unreachable, and reaching the end of the function throws a TypeError. Checked on PHP 8.2 and 8.5: if (false) { return; } fails with "A never-returning function must not return", and falling off the end throws "never-returning function must not implicitly return".

@lacatoire
lacatoire merged commit 18a1cc5 into php:master Oct 5, 2026
3 checks passed
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.

A "never" function is checked at compile time and runtime, and may still throw

2 participants