有没有办法在php中序列化匿名函数?
我找到了这个http://www.htmlist.com/development/extending-php-5-3-closures-with-serialization-and-reflection/ http://www.htmlist.com/development/extending-php-5-3-closures-with-serialization-and-reflection/
protected function _fetchCode()
{
// Open file and seek to the first line of the closure
$file = new SplFileObject($this->reflection->getFileName());
$file->seek($this->reflection->getStartLine()-1);
// Retrieve all of the lines that contain code for the closure
$code = '';
while ($file->key() < $this->reflection->getEndLine())
{
$code .= $file->current();
$file->next();
}
// Only keep the code defining that closure
$begin = strpos($code, 'function');
$end = strrpos($code, '}');
$code = substr($code, $begin, $end - $begin + 1);
return $code;
}
但这取决于闭包的内部实现。
未来有计划实现闭包序列化吗?
看看我在这里关于 PHP Super Closure 的回复:
例外:不允许序列化“Closure” https://stackoverflow.com/questions/13734224/exception-serialization-of-closure-is-not-allowed/19730234#19730234
我希望它有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)