在php中序列化匿名函数 [英] Serializing anonymous functions in php
本文介绍了在php中序列化匿名函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以在php中序列化一个匿名函数?
is there any way to serialize an anonymous function in php?
我找到了这个 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;
}
但这取决于闭包的内部实现.
but it depends on the internal implementation of closure.
将来有什么计划实现闭包序列化吗?
are there any future plans to implement closure serialization?
推荐答案
在这里查看我有关PHP Super Closure的答复:
Take a look to my response here about PHP Super Closure :
希望对您有帮助.
这篇关于在php中序列化匿名函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文