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

Support for aliases? #9372

Closed
jsanahuja opened this issue Feb 22, 2023 · 7 comments · Fixed by #9375
Closed

Support for aliases? #9372

jsanahuja opened this issue Feb 22, 2023 · 7 comments · Fixed by #9375
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement good first issue Help wanted

Comments

@jsanahuja
Copy link
Contributor

jsanahuja commented Feb 22, 2023

Psalm does not seem to take PHP aliases into account. Examples:

Is this the expected behavior?

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/9d70fdf31d
<?php

$str = "1|2|3|4|5|6";
$parts = explode('|', $str);

if (count($parts) != 6) {
    die('6 parts required!');
}

[$a, $b, $c, $d, $e, $f] = $parts;

print_r([$a, $b, $c, $d, $e, $f]);
Psalm output (using commit c8f7b7e):

No issues!
https://psalm.dev/r/8a26a0a0f9
<?php

$str = "1|2|3|4|5|6";
$parts = explode('|', $str);

if (sizeof($parts) != 6) {
    die('6 parts required!');
}

[$a, $b, $c, $d, $e, $f] = $parts;

print_r([$a, $b, $c, $d, $e, $f]);
Psalm output (using commit c8f7b7e):

INFO: PossiblyUndefinedIntArrayOffset - 10:6 - Possibly undefined array key

INFO: PossiblyUndefinedIntArrayOffset - 10:10 - Possibly undefined array key

INFO: PossiblyUndefinedIntArrayOffset - 10:14 - Possibly undefined array key

INFO: PossiblyUndefinedIntArrayOffset - 10:18 - Possibly undefined array key

INFO: PossiblyUndefinedIntArrayOffset - 10:22 - Possibly undefined array key

@weirdan
Copy link
Collaborator

weirdan commented Feb 22, 2023

Not expected as in 'incorrect'.

@weirdan
Copy link
Collaborator

weirdan commented Feb 22, 2023

Aliases reference: https://www.php.net/manual/en/aliases.php

@orklah
Copy link
Collaborator

orklah commented Feb 22, 2023

Adding sizeof here:

return self::hasNonEmptyCountOrStrlenEqualityCheck($conditional, $min_count, ['count']);
should be enough :)

@orklah orklah added easy problems Issues that can be fixed without background knowledge of Psalm Help wanted good first issue labels Feb 22, 2023
@jsanahuja
Copy link
Contributor Author

May I send a pull request fixing it @weirdan and @orklah?

@weirdan
Copy link
Collaborator

weirdan commented Feb 22, 2023

You absolutely can.

@jsanahuja
Copy link
Contributor Author

jsanahuja commented Feb 22, 2023

Done, thanks!

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

Successfully merging a pull request may close this issue.

3 participants