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

Invalid PossiblyUndefinedVariable when try/catch/finally #6286

Closed
ArtemGoutsoul opened this issue Aug 11, 2021 · 3 comments · May be fixed by #7688
Closed

Invalid PossiblyUndefinedVariable when try/catch/finally #6286

ArtemGoutsoul opened this issue Aug 11, 2021 · 3 comments · May be fixed by #7688

Comments

@ArtemGoutsoul
Copy link
Contributor

With this code

function func(string $name): void {
    try {
    }
    catch (Throwable $e) {
        if ($name === 'stuff') throw $e;
        echo $e->getCode();
    }
    finally {
    }
}

I get and error for line echo $e->getCode();:

INFO: PossiblyUndefinedVariable - 9:14 - Possibly undefined variable $e defined in try block

Funny thing, if I remove if ($name === 'stuff') throw $e; or if I remove finally, the error disappears...

Link: https://psalm.dev/r/e9822c86ed

@psalm-github-bot
Copy link

I found these snippets:

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

function func(string $name): void {
    try {
    }
    catch (Throwable $e) {
        if ($name === 'stuff') throw $e;
        echo $e->getCode();
    }
    finally {
    }
}
Psalm output (using commit 7c339c1):

INFO: PossiblyUndefinedVariable - 8:14 - Possibly undefined variable $e defined in try block

@weirdan
Copy link
Collaborator

weirdan commented Nov 21, 2022

Not reproducible anymore: https://psalm.dev/r/e9822c86ed

@weirdan weirdan closed this as completed Nov 21, 2022
@psalm-github-bot
Copy link

I found these snippets:

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

function func(string $name): void {
    try {
    }
    catch (Throwable $e) {
        if ($name === 'stuff') throw $e;
        echo $e->getCode();
    }
    finally {
    }
}
Psalm output (using commit 7869cb5):

No issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants