加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

在php中序列化匿名函数

发布时间:2020-12-13 17:52:42 所属栏目: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 =
有没有办法在 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 Super Closure的回复:

Exception: Serialization of ‘Closure’ is not allowed

我希望它有所帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读