class foo {
function bar(callable $callable) {
$callable();
}
function printStr() {
echo "hi";
}
}
$foo = new foo();
$foo->bar(function () {
$this->printStr(); // Using $this when not in object context
});
是的,您需要传递一个匿名函数来调用foo类的方法.就像JS一样.如何才能做到这一点?