Home  >  Q&A  >  body text

Replace create_function() with something else for PHP8

So I have a plugin that used to work fine, but for a few days it threw me an error:

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

After some searching, I found out that this is because create_function() has been deprecated in PHP 8.

Now the exact line causing the problem is:

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

I tried changing it to:

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

But it doesn't work. So if anyone could point me in the right direction, and I'm new to PHP, that would be great.

P粉197639753P粉197639753333 days ago572

reply all(1)I'll reply

  • P粉771233336

    P粉7712333362023-10-26 19:49:25

    try

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

    reply
    0
  • Cancelreply