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

Callable should only allow public methods if used as arg in a non-$this/self context #10823

Closed
kkmuffme opened this issue Mar 13, 2024 · 1 comment · Fixed by #10839
Closed

Comments

@kkmuffme
Copy link
Contributor

https://psalm.dev/r/7a6d5d9849

Copy link

I found these snippets:

https://psalm.dev/r/7a6d5d9849
<?php

/**
 * @param callable $arg
 * @return void
 */
function foo($arg) {
    call_user_func($arg);
}

class A {
    public function __construct() {
		foo(array($this, 'run')); // this should be an error, since it's a fatal
        $this->bar(array($this, 'run')); // this is fine
    }
    
    private function run() : void {
        echo "done";
    }

    /**
     * @param callable $arg
     * @return void
     */
    protected function bar($arg) {
        call_user_func($arg);
    }
}

$a = new A();
Psalm output (using commit ef3b018):

INFO: UnusedVariable - 30:1 - $a is never referenced or the value is not used

kkmuffme added a commit to kkmuffme/psalm that referenced this issue Mar 19, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Mar 19, 2024
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Mar 19, 2024
weirdan pushed a commit to kkmuffme/psalm that referenced this issue Mar 20, 2024
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