Alapan Das
Alapan Das

Reputation: 18618

replacing create_function() with something else for PHP8

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.

Upvotes: 5

Views: 17103

Answers (1)

Guido Faecke
Guido Faecke

Reputation: 684

Try

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

Upvotes: 12

Related Questions