Skip to content

uniqid: Tighten return type to non-falsy-string - #6242

Merged
staabm merged 1 commit into
phpstan:2.2.xfrom
tkw1536:uniqid-non-falsy-string
Aug 21, 2026
Merged

uniqid: Tighten return type to non-falsy-string#6242
staabm merged 1 commit into
phpstan:2.2.xfrom
tkw1536:uniqid-non-falsy-string

Conversation

@tkw1536

@tkw1536 tkw1536 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

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:

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

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
@staabm
staabm merged commit 84321ea into phpstan:2.2.x Aug 21, 2026
752 of 755 checks passed
@staabm

staabm commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Thank you

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.

3 participants