Skip to content
Advertisement

PHP 7.2 Function create_function() is deprecated

I have used create_function() in my application below.

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

But for PHP 7.2.0, create_function() is deprecated.

How do I rewrite my code above for PHP 7.2.0?

Advertisement

Answer

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]);
};
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement