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

Incorrect PossiblyUndefinedVariable after try/catch statement #5973

Open
gdejong opened this issue Jun 22, 2021 · 1 comment · May be fixed by #7688
Open

Incorrect PossiblyUndefinedVariable after try/catch statement #5973

gdejong opened this issue Jun 22, 2021 · 1 comment · May be fixed by #7688

Comments

@gdejong
Copy link
Contributor

gdejong commented Jun 22, 2021

Hi, in this case $data is always defined but a PossiblyUndefinedVariable error is triggered.

https://psalm.dev/r/6fda415fad

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/6fda415fad
<?php

class A {
    public function __construct(int $a) {
        try {
            switch($a){
            	case 1:
                	$data = "one";
                	break;
            	default:
                	throw new RuntimeException("not one");
        	}
        } catch(Throwable $e) {
            $data = $e->getMessage();
        }
        
        echo $data;
    }
}

new A(2);
Psalm output (using commit 6d4d166):

INFO: PossiblyUndefinedVariable - 17:14 - Possibly undefined variable $data defined in try block

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