在PHP手冊http://www.php.net/manual/en/function.session-set-save-handler.php的這個頁面上,我發現這個函數規範:bool session_set_save_handler (callable $open , callable $close , callable $read , callable $write , callable $destroy , callable $gc)
它指示所有參數應該是回調。但是,我也發現,頁這個例子:爲什麼數組可以用作回調
class FileSessionHandler
{
private $savePath;
function open($savePath, $sessionName)
{
$this->savePath = $savePath;
if (!is_dir($this->savePath)) {
mkdir($this->savePath, 0777);
}
return true;
}
function close()
{
...
}
...
}
$handler = new FileSessionHandler();
session_set_save_handler(
array($handler, 'open'),
array($handler, 'close'),
array($handler, 'read'),
array($handler, 'write'),
array($handler, 'destroy'),
array($handler, 'gc')
);
在session_set_save_handler
每個參數是一個陣列,其中第一元素是處理程序對象和第二字符串。
爲什麼這些數組可以用作回調?我引用了Array,回調手冊,但沒有發現如何實現這一點。
只需點擊參數前面的「Callable」即可閱讀說明書:http://www.php.net/language.types.callable.php – hakre 2013-04-07 16:57:37
http://php.net/manual/ en/language.types.callable.php - 「傳遞」下的第二個句子。 – Jon 2013-04-07 16:57:42
你在你的問題中寫下你已經閱讀過手冊頁。因此,可能值得回想一下你不明白的陣列中的哪一部分? – hakre 2013-04-07 17:00:34