PHP 7.2 函数 create_function() 已弃用 [英] PHP 7.2 Function create_function() is deprecated

查看:35
本文介绍了PHP 7.2 函数 create_function() 已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的应用程序中使用了 create_function.

I have used create_function in my application below.

$callbacks[$delimiter] = create_function('$matches', "return '$delimiter' . strtolower($matches[1]);");

但对于 PHP 7.2.0,create_function() 已弃用.

But for PHP 7.2.0, the create_function() is deprecated.

如何在 PHP 7.2.0 上修复我上面的代码.

How to fix my code above on PHP 7.2.0.

推荐答案

您应该能够使用 匿名函数(又名闭包),调用父作用域 $delimiter 变量,如下所示:

You should be able to use an Anonymous Function (aka Closure) with a call to the parent scoped $delimiter variable, like so:

$callbacks[$delimiter] = function($matches) use ($delimiter) {
    return $delimiter . strtolower($matches[1]);
};

这篇关于PHP 7.2 函数 create_function() 已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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