在php中序列化匿名函数 [英] Serializing anonymous functions in php

查看:30
本文介绍了在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 :

例外:不允许序列化Closure"

希望能帮到你.

这篇关于在php中序列化匿名函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆