Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw PossiblyFalseArgument on pass false|list<string> to in_array #9764

Closed
vjik opened this issue May 9, 2023 · 3 comments
Closed
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement good first issue Help wanted

Comments

@vjik
Copy link
Contributor

vjik commented May 9, 2023

https://psalm.dev/r/e229d24bd7

Var is false|list<string>, but PossiblyFalseArgument into in_array do not throw.

Expected:

[PossiblyFalseArgument](https://psalm.dev/104) - 7:26 - Argument 2 of in_array cannot be false, possibly array<array-key, mixed> value expected
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/e229d24bd7
<?php

function testFn(string $value): bool {
    $parts = preg_split('/[\s,]+/', $value, flags: PREG_SPLIT_NO_EMPTY);
    
    /** @psalm-trace $parts */
    
    return in_array('1', $parts);
}
Psalm output (using commit d4c5f85):

INFO: Trace - 8:5 - $parts: false|list<string>

@orklah
Copy link
Collaborator

orklah commented May 9, 2023

It will throw if you put this config to false: https://psalm.dev/docs/running_psalm/configuration/#ignoreinternalfunctionfalsereturn

It does not by default because of the bad habit PHP had to return exotic false/null when given invalid input before PHP 8 (so Psalm would ignore them to preven bothering you to check for every possible exotic value). I'd be open to change the default value for this config in order to report them by default now that PHP 8 cleaned up everything

@weirdan
Copy link
Collaborator

weirdan commented Feb 10, 2024

Fixed in #10211

@weirdan weirdan closed this as completed Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement good first issue Help wanted
Projects
None yet
Development

No branches or pull requests

3 participants