(php)如何在array_filter中将类方法作为回调传递?

use*_*204 2 php oop function

array_filter用php函数调用时你应该这样做

function myFunc($e) {
    return something($e);
}
array_filter($myArray,"myFunc");
Run Code Online (Sandbox Code Playgroud)

但是我如何传递一个类方法呢?(例如,静态或非静态)

class A {
    public function foo() {
        //code
        $a = array_filter($array,"self::myFilter");
        //or if myFilter is an instance method
        $a = array_filter($array,"this->myFilter");
    }
    public (static)? function myFilter($e) {return something($e);}
}
Run Code Online (Sandbox Code Playgroud)

我需要因为我将在类中的其他地方重用我的过滤器函数,我尝试在静态变量中使用匿名函数,但我得到错误

Mat*_*wne 6

这适用于实例方法版本:

class A {
    public function foo() {
        $a = array_filter($array, array($this, "myFilter"));
    }
    public function myFilter($e) {return something($e);}
}
Run Code Online (Sandbox Code Playgroud)

http://php.net/manual/en/language.types.callable.php