replacing create_function() with something else for PHP8

12.8k Views Asked by At

So I have a plugin that was working fine previously, but for a few days now it is throwing me an error as:

PHP Fatal error: Uncaught Error: Call to undefined function create_function()

After a bit of searching, I found out that this is because create_function() is deprecated in PHP 8.

Now the exact line that causes the issue is this:

$callback_2 = create_function('$matches', 'return "[" . str_replace("|", "", $matches[1]) . "]";');

I tried changing this to:

$callback_2 = function(){
 ('$matches', return "[" . str_replace("|", "", $matches[1]) . "]";);
}

But it's not working. So it would be great if someone could point me in the right direction also I am very new to PHP.

1

There are 1 best solutions below

0
Guido Faecke On BEST ANSWER

Try

$callback_2 = function($matches) {
    return "[" . str_replace("|", "", $matches[1]) . "]";
};