Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

Try

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading