psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Non-static methods called statically should report error

Open kkmuffme opened this issue 2 years ago • 1 comments

https://psalm.dev/r/8d8e02aefb

kkmuffme avatar Sep 24 '22 18:09 kkmuffme

I found these snippets:

https://psalm.dev/r/8d8e02aefb
<?php

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

class foo {
    public function __construct() {        
        // should give error, since "hello" isn't static
        do_action( array( __CLASS__, 'hello' ) );
        do_action( array( foo::class, 'hello' ) );
        do_action( array( 'foo', 'hello' ) );
        do_action( 'foo::hello' );
    }
    
    /**
     * @return string
     */
 	public function hello() {
        return 'hello';
    }
}
Psalm output (using commit 028ac7f):

No issues!

psalm-github-bot[bot] avatar Sep 24 '22 18:09 psalm-github-bot[bot]