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

Undefined index warnings and notices in ClosureAnalyzer #5255

Closed
mertvetsky opened this issue Feb 20, 2021 · 3 comments · Fixed by #5256
Closed

Undefined index warnings and notices in ClosureAnalyzer #5255

mertvetsky opened this issue Feb 20, 2021 · 3 comments · Fixed by #5256
Labels

Comments

@mertvetsky
Copy link

https://psalm.dev/r/c6cc4713ae

<br />
<b>Notice</b>:  Undefined index: $b in <b>/var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClosureAnalyzer.php</b> on line <b>137</b><br />
<br />
<b>Notice</b>:  Trying to get property 'parent_nodes' of non-object in <b>/var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClosureAnalyzer.php</b> on line <b>137</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClosureAnalyzer.php</b> on line <b>139</b><br />
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/c6cc4713ae
<?php
if (rand(0, 1)) {
    $b = 321;
}
$a = function () use ($b):int  {
    return $b;
};
echo $a();
Psalm output (using commit e93e532):

INFO: PossiblyUndefinedVariable - 5:23 - Possibly undefined variable $b, first seen on line 3

INFO: MixedReturnStatement - 6:12 - Could not infer a return type

INFO: MixedInferredReturnType - 5:27 - Could not verify return type 'int' for /var/www/vhosts/psalm.dev/httpdocs/src/somefile.php:5:45:-:closure

INFO: UnusedVariable - 3:5 - $b is never referenced or the value is not used

@weirdan weirdan added the bug label Feb 20, 2021
@weirdan
Copy link
Collaborator

weirdan commented Feb 20, 2021

@muglug how do you feel about introducing an error handler to convert all notices/warnings/etc into exceptions?

weirdan added a commit to weirdan/psalm that referenced this issue Feb 20, 2021
@muglug
Copy link
Collaborator

muglug commented Feb 21, 2021

how do you feel about introducing an error handler to convert all notices/warnings/etc into exceptions?

I think that's a great idea! Normally a notice pre-empts a fatal error anyway.

muglug pushed a commit that referenced this issue Feb 21, 2021
This was referenced Mar 15, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants