How to fix ‘Function create_function() is deprecated’ warning with PHP 7.2?

Spread the love

Sometimes, we want to fix ‘Function create_function() is deprecated’ warning with PHP 7.2.

In this article, we’ll look at how to fix ‘Function create_function() is deprecated’ warning with PHP 7.2.

How to fix ‘Function create_function() is deprecated’ warning with PHP 7.2?

To fix ‘Function create_function() is deprecated’ warning with PHP 7.2, we can create a anonymous function.

For instance, we write

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

to define an anonymous function with function that takes the $matches parameter and use the $delimiter variable from the parent scope.

And we assign the anonymous function to $callbacks[$delimiter].

Conclusion

To fix ‘Function create_function() is deprecated’ warning with PHP 7.2, we can create a anonymous function.

Leave a Reply

Your email address will not be published.