我在使用 getDelayed 中的結果回呼來呼叫方法時遇到問題,所以我寄信給了開發者。
如果您想使用非靜態方法作為回呼,請使用以下格式:array($obj, 'method'); 例如:
<?php
class foo {
private $M = false;
public function __construct() {
$this->M = new Memcached();
$this->M->addServer('localhost', 11211);
$this->M->set('a', 'test');
}
public function test() {
$this->M->getDelayed(array('a'), false, array($this, 'fun'));
}
public function fun() {
echo "Great Success!";
}
}
$f = new foo();
$f->test();
?>
或者,另一種方法是:
<?php
類別 foo {
公開 $M = false;
公開 函式 __construct() {
$this->M = new Memcached();
$this->M->addServer('localhost', 11211);
$this->M->set('a', 'test');
}
公開 函式 fun() {
echo "Great Success!";
}
}
$f = new foo();
$f->M->getDelayed(array('a'), false, array($f, 'fun'));
?>
運作良好,感謝 Andrei :)