Repository navigation
void: document that returning a value is a compile-time error - #5920
Merged
Merged
Conversation
lacatoire
reviewed
Oct 8, 2026
| <type>void</type> function is a compile-time error, even if the | ||
| <literal>return</literal> would not be reached during execution. | ||
| This includes <literal>return null;</literal>; use a bare | ||
| <literal>return;</literal> to exit the function early. |
Member
There was a problem hiding this comment.
Suggested change
| <literal>return;</literal> to exit the function early. | |
| <literal>return;</literal> to exit the function early. The | |
| <literal>null</literal> mentioned below is only the implicit value of | |
| the call. |
Contributor
Author
There was a problem hiding this comment.
Thanks, applied your suggestion in 3cf5d28.
lacatoire
requested changes
Oct 8, 2026
Co-authored-by: Louis-Arnaud <lacatoire@users.noreply.github.com>
lacatoire
approved these changes
Oct 8, 2026
Member
|
Thanks @SatvikMishra08 ! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #5389
This adds the point from the issue that @DanielEScherzer agreed should be documented: a
returnwith an expression in avoidfunction is a compile-time error, even when thereturncan't be reached. I also mentionedreturn null;, since that's the case people usually hit, and PHP's error message points them to a barereturn;.The other points in the issue got pushback in the discussion (exceptions, TypeErrors, "return-only type" is already in the first sentence), so I left them out. This mirrors what #5906 did for
never.