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

Bug with isset and !empty in 0.12.51 #3990

Closed
murtukov opened this issue Oct 23, 2020 · 12 comments
Closed

Bug with isset and !empty in 0.12.51 #3990

murtukov opened this issue Oct 23, 2020 · 12 comments

Comments

@murtukov
Copy link

Bug report

The simple check with isset() and !empty()stopped to work as expected, when I updated to 0.12.51. It worked without errors from 0.12.33 to 0.12.50. I couldn't reproduce it in the playground.

Code snippet that reproduces the problem

if (isset($description)) {
    echo $description;
}

Expected output

No errors.

Actual output

Undefined variable: $description

@mergeable
Copy link

mergeable bot commented Oct 23, 2020

This bug report is missing a link to reproduction on phpstan.org.
It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

I couldn't reproduce it in the playground.

This doesn't help me solve the problem. Can you show more surrounding code? And is it inside function or in the global scope?

@murtukov
Copy link
Author

murtukov commented Oct 23, 2020

@ondrejmirtes I've created an empty Symfony project with PHPStan 0.12.51 to reproduce this issue.

https://github.com/murtukov/phpstan-reproduce-issue

Just composer install and vendor/bin/phpstan analyse src

@murtukov
Copy link
Author

murtukov commented Oct 23, 2020

I am using the extract function to initialize variables, e.g.:

protected function buildConfigLoader(array $config): void
{
    /**
     * @var array       $fields
     * @var string|null $description
     * @var array|null  $interfaces
     * @var string|null $resolveType
     * [...]
     *
     * @phpstan-ignore-next-line
     */
    extract($config);

    $configLoader = Collection::assoc();

    if (isset($description)) {
        $configLoader->addItem('description', $description);
    }

    // ...

This is the line in the real project, where this error occurs:
https://github.com/overblog/GraphQLBundle/blob/master/src/Generator/TypeBuilder.php#L192

@ondrejmirtes
Copy link
Member

@murtukov
Copy link
Author

@ondrejmirtes this reproduction also throws Variable $description in isset() is never defined. which is not present in my case.

@ondrejmirtes
Copy link
Member

@murtukov Depends on the level you're running.

@murtukov
Copy link
Author

murtukov commented Oct 24, 2020

@ondrejmirtes I'm using level 7 in my project, it still doesn't throw Variable $description in isset() is never defined., while in the playground it throws this message on every level, except 0.

So is this a bug (the issue described in the first message)?

@ondrejmirtes
Copy link
Member

This is what happens when I run level 5 on your provided example repository:

$ vendor/bin/phpstan analyse -l 5 src
 2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ----------------------------------------------------
  Line   Controller/IndexController.php
 ------ ----------------------------------------------------
  11     Variable $description in isset() is never defined.
  12     Undefined variable: $description
  16     Undefined variable: $info
 ------ ----------------------------------------------------


 [ERROR] Found 3 errors

The message Variable $description in isset() is never defined. is there.

@murtukov
Copy link
Author

murtukov commented Oct 24, 2020

@ondrejmirtes you are right, the reason why I didn't get this error in my real project, is that I suppressed it.

But the main issue is still there: 0.12.51 introduces Undefined variable. Is it a bug or intended to be so?

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@d3e7b9c

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants