gpt4 book ai didi

php - 在php中序列化匿名函数

转载 作者:可可西里 更新时间:2023-11-01 12:57:52 26 4
gpt4 key购买 nike

有什么方法可以在 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;
}

但这取决于闭包的内部实现。

future 有没有实现闭包序列化的计划?

最佳答案

在这里查看我对 PHP Super Closure 的回复:

Exception: Serialization of 'Closure' is not allowed

希望对你有帮助。

关于php - 在php中序列化匿名函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16534245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com