PHP 7.2 Function create_function() is deprecated

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]);
};

I would like to contribute with a very simple case I found in a Wordpress Theme and seems to work properly:

Having the following add_filter statement:

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

Replace it for:

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

We can see the usage of function(), very typical function creation instead of a deprecated create_function() to create functions. Hope it helps.

Tags:

Php