相关疑难解决方法(0)

例外:不允许序列化'Closure'

所以我不确定我要向你们展示什么,如果你需要更多代码,请不要犹豫,问:

所以这个方法将在我们的应用程序中为Zend设置initMailer:

protected function _initMailer()
{
    if ('testing' !==  APPLICATION_ENV) {
        $this->bootstrap('Config');
        $options = $this->getOptions();
        $mail = new Zend_Application_Resource_Mail($options['mail']);
    }elseif ('testing'  ===  APPLICATION_ENV) {
        //change the mail transport only if dev or test
        if (APPLICATION_ENV <> 'production') {

            $callback = function()
            {
                return 'ZendMail_' . microtime(true) .'.tmp';
            };

            $mail = new Zend_Mail_Transport_File(
                array('path' => '/tmp/mail/',
                        'callback'=>$callback
                )
            );

            Zend_Mail::setDefaultTransport($mail);
        }
    }


    return $mail;
}
Run Code Online (Sandbox Code Playgroud)

你可以看到它所在的闭包.当我运行任何使用这段代码的测试时,我得到:

Exception: Serialization of 'Closure' is not allowed 
Run Code Online (Sandbox Code Playgroud)

因此,与这种"封闭"有关的所有测试都失败了.所以我在这里问你们应该做些什么.

为了澄清上述情况,所有人都在说我们发送的任何电子邮件都要将有关该电子邮件的信息存储在文件的/ tmp/mail /目录下的文件夹中.

php serialization closures exception

49
推荐指数
3
解决办法
8万
查看次数

获取匿名函数的字符串表示形式

假设我有一个匿名的PHP函数,如下所示:

<?php
$l = function() { echo "hello world"; };
Run Code Online (Sandbox Code Playgroud)

是否有可能获得匿名函数的字符串表示$l,即包含函数体的字符串?

我试了几件事:

  • echo $l; PHP Catchable致命错误:类Closure的对象无法转换为字符串
  • var_dump($l); 类闭包#1(0){}
  • echo $l->__toString();:调用未定义的方法Closure :: __ toString()
  • get_class_methods($l)返回array('bind', 'bindTo'),所以似乎没有未记录的方法
  • $r = new ReflectionClass($l);:getProperties(),getConstants()和getStaticProperties()都是空的,也$r->__toString()没有返回任何有用的东西.

我在代码中并不需要这个,我只是认为如果出现问题可能对日志记录有用.在我无法自己提出解决方案后,我很好奇是否有可能.

php closures anonymous-function

9
推荐指数
1
解决办法
2301
查看次数