在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