PHP 7.2 function create_function() is deprecated
P粉831310404
P粉831310404 2024-01-16 11:05:38
0
2
328

I am usingcreate_function()in the application below.

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

But as of PHP 7.2.0,create_function()is deprecated.

How to rewrite the above code for PHP 7.2.0?

P粉831310404
P粉831310404

reply all (2)
P粉354948724

I would like to contribute a very simple case I found in a WordPress theme and it seems to work fine:

Has the followingadd_filterstatement:

add_filter( 'option_page_capability_' . ot_options_id(), create_function( '$caps', "return '$caps';" ), 999 );

Replace it with:

add_filter( 'option_page_capability_' . ot_options_id(), function($caps) {return $caps;},999);

We can see the usage of function(), which is a very typical function creation, instead of using the deprecated create_function() to create a function.

    P粉287726308

    You should be able to useanonymous functions(aka closures) calls to parent scope$delimitervariables like this:

    $callbacks[$delimiter] = function($matches) use ($delimiter) { return $delimiter . strtolower($matches[1]); };
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!