Skip to content

Conversation

@jlherren
Copy link
Contributor

Fix handling of non-bools as $strict parameter and omit false from return type when $string is valid base64.

This is useful when constant binary strings are required in code, e.g.:

$emptyZipFile = base64_decode('UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA==', true);

Related to phpstan/phpstan#7866

- Detect when the result cannot be false
- Correctly treat non-boolean $strict parameter

return new StringType();
if ($isStrict->maybe() && $isValidBase64->maybe()) {
return new BenevolentUnionType([new StringType(), new ConstantBooleanType(false)]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a benevolent one ? I think it should be a simple union

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured if the strictness is unclear (which almost never happens), then a benevolent union is better (based on the previous behavior). But of course this can be changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, didn't know it was the previous behavior.

Indeed https://phpstan.org/r/54560d00-fc90-4e4f-bc72-74a670a8e415

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.

2 participants