I am using create_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粉3549487242024-01-17 10:01:58
I would like to contribute a very simple case I found in a WordPress theme and it seems to work fine:
Has the following add_filter statement:
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粉2877263082024-01-17 00:49:46
You should be able to use anonymous functions (aka closures) calls to parent scope $delimiter
variables like this:
$callbacks[$delimiter] = function($matches) use ($delimiter) { return $delimiter . strtolower($matches[1]); };