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

First Class Callable: Catch UndefinedMethod #10170

Closed
jarstelfox opened this issue Aug 31, 2023 · 1 comment · Fixed by #10691
Closed

First Class Callable: Catch UndefinedMethod #10170

jarstelfox opened this issue Aug 31, 2023 · 1 comment · Fixed by #10691

Comments

@jarstelfox
Copy link
Contributor

https://psalm.dev/r/b6bb608bf8

This syntax under the hood uses Closure::fromCallable, which will bind to the current scope. It seems like we should be able to statically answer if a method/class would be undefined.

@psalm-github-bot
Copy link

I found these snippets:

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

class FuncLib {
    public static function MyFunc(): void {
        echo "MyFunc";
    }
}
class A {
    /** @var Closure */
    public $callbackWillWork;
    
    /** @var Closure */
    public $callbackBroken;
    
    public function __construct() {
       $this->callbackWillWork = FuncLib::MyFunc(...);
       $this->callbackBroken = FuncLib::DOES_NOT_EXIST(...);
    }
}
Psalm output (using commit 77650e7):

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