You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP 7.3中create_function()废弃,如何重写对应代码?

解决PHP 7.3中create_function()废弃的报错问题

升级PHP从5.6到7.3后,出现报错:

PHP Deprecated: Function create_function() is deprecated in magiczoomplus/magiczoomplus.module.core.class.php on line 78

原代码片段:

'restore-speed' => create_function('&$params', 'return $params->checkValue("restore-speed","-1")?$params->getValue("expand-speed"):$params->getValue("restore-speed");')));

重写方案

PHP 7.2及以上版本已废弃create_function(),应使用匿名函数替代,修改后的代码如下:

'restore-speed' => function(&$params) {
    return $params->checkValue("restore-speed", "-1") ? $params->getValue("expand-speed") : $params->getValue("restore-speed");
}

修改说明

  • 用匿名函数语法function(&$params) { ... }替换create_function()的字符串拼接写法,逻辑完全一致
  • 将原代码中的HTML实体"替换为原生双引号",匿名函数体内无需转义
  • 保留$params的引用传递(&$params),确保和原代码的参数传递行为一致

内容的提问来源于stack exchange,提问作者Launch Athira

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 11:28:18