uniqid: Tighten return type to non-falsy-string - #6242
Merged
Conversation
This commit tightens the return type of the 'uniqid' function from non-empty-string to non-falsy-string. The official documentation [1] of the uniqid function says: > With an empty prefix, the returned string will be 13 characters long. If more_entropy is true, it will be 23 characters. This implies that the returned string will be of length strlen(prefix) + (more_entropy ? 23 : 13). In either case, it will be of at least length 13. But the only falsy strings are '0' and '' (both of length less than 13) [2]. Hence the return value will always be a non-falsy-string. [1] https://www.php.net/manual/en/function.uniqid.php [2] https://www.php.net/manual/en/language.types.boolean.php
VincentLanglet
approved these changes
Aug 21, 2026
staabm
approved these changes
Aug 21, 2026
Contributor
|
Thank you |
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.
This PR tightens the return type of the 'uniqid' function from non-empty-string to non-falsy-string. The official documentation [1] of the uniqid function says:
This implies that the returned string will be of length
strlen(prefix) + (more_entropy ? 23 : 13).In either case, it will be of at least length 13. But the only falsy strings are
'0'and''(both of length less than 13) [2]. Hence the return value will always be a non-falsy-string.[1] https://www.php.net/manual/en/function.uniqid.php
[2] https://www.php.net/manual/en/language.types.boolean.php