6
有沒有什麼辦法在PHP中序列化匿名函數?序列化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;
}
,但是這取決於內部實現封閉。
是否有任何未來的計劃來實現閉包序列化?
你想在某些時候將PHP函數傳遞給PHP?爲什麼? – BlitZ 2013-05-14 02:56:13
假設我有一些用戶界面組件庫,我想給用戶一定程度的自定義輸出(通過匿名函數)。而且我希望能夠在會話中保存對象的狀態。 – Jarry 2013-05-14 04:01:48