close

[Solved] PHP 7.2 Function create_function() is deprecated

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error PHP 7.2 Function create_function() is deprecated in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How PHP 7.2 Function create_function() is deprecated Error Occurs?

Today I get the following error PHP 7.2 Function create_function() is deprecated in php.

How To Solve PHP 7.2 Function create_function() is deprecated Error ?

  1. How To Solve PHP 7.2 Function create_function() is deprecated Error ?

    To Solve PHP 7.2 Function create_function() is deprecated Error You should be able to use an Anonymous Function (aka Closure) with a call to the parent scoped $delimiter variable, like so:

  2. PHP 7.2 Function create_function() is deprecated

    To Solve PHP 7.2 Function create_function() is deprecated Error You should be able to use an Anonymous Function (aka Closure) with a call to the parent scoped $delimiter variable, like so:

Solution 1

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

Solution 2

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.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment