解决 Serialization of closure failed: The closure was not found within the abstract syntax tree.

分类:PHP |

这里记录一个解决关于php下 SerializableClosure 使用的实例:


PHP User Notice 'yii\base\ErrorException' with message 'Serialization of closure failed: The closure was not found within the abstract syntax tree.'


in /www/dev.xxx.cn/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php:116


Stack trace:

#0 [internal function]: yii\base\ErrorHandler->handleError(1024, 'Serialization o...', '/www/dev.xxx...', 116, Array)

#1 /www/dev.xxx.cn/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(116): trigger_error('Serialization o...', 1024)

#2 [internal function]: SuperClosure\SerializableClosure->serialize()

#3 /www/dev.xxx.cn/vendor/jeremeamia/SuperClosure/src/Serializer.php(70): serialize(Object(SuperClosure\SerializableClosure))

#4 /www/dev.xxx.cn/console/controllers/TestController.php(34): SuperClosure\Serializer->serialize(Object(Closure))

#5 [internal function]: console\controllers\TestController->actionApiTest()

#6 /www/dev.xxx.cn/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

#7 /www/dev.xxx.cn/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)

#8 /www/dev.xxx.cn/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('api-test', Array)

#9 /www/dev.xxx.cn/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('api-test', Array)

#10 /www/dev.xxx.cn/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('test/api-test', Array)

#11 /www/dev.xxx.cn/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('test/api-test', Array)

#12 /www/dev.xxx.cn/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))

#13 /www/dev.xxx.cn/yii(27): yii\base\Application->run()

#14 {main} 



起因: php环境由原来的 php5.6 升级为 php7.3.12,  

顺便说一下  以后 mcrypt  ((PHP 4 >= 4.0.2, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)) 内的方法 需要单独编译扩展才可以使用


在执行cli的计划任务时报以上错误: 

不支持  echo $x ?? '111'; 这种写法


测试方法: 

$serializer_obj = new \SuperClosure\Serializer();

$x = function (){echo 123;};

$y = $serializer_obj->serialize($x);

$z = $serializer_obj->unserialize($y);

$z();


$c = opcache_get_configuration();

print_r($c);

exit;


解决方法: 

关闭 php.ini 下的  opcache.enable_cli


opcache.enable_cli=1

改为: 

opcache.enable_cli=0