OOP类中的PHP FILTER_CALLBACK

1 php filter

嗨,我一直在玩phps过滤器类获取并遇到过filter_callback过滤器的问题.

以下粗略的代码工作,但每次都显示错误

警告:filter_var()[function.filter-var]:第一个参数应该是第12行/Users/Rob/sites/test_val.php中的有效回调

class test

{

public function callback($string)
{

$var = filter_var($string, FILTER_CALLBACK, array('options' => $this->foo($string)));

} 

public function foo($string){

echo $string;


}

}


$test = new test();

$string = 'test';

$tested = $test->callback($string);
Run Code Online (Sandbox Code Playgroud)

我是正确调用函数还是有不同的方法?

ale*_*lex 8

$this->foo($string)
Run Code Online (Sandbox Code Playgroud)

...应该...

array($this, 'foo')
Run Code Online (Sandbox Code Playgroud)

使用方法作为回调时,需要以这种方式提供引用.

文档.