Skip to content
PHP Logo

What alternatives can be used to replace deprecated functions in PHP, such as create_function()?

The create_function() function in PHP has been deprecated since version 7.2 due to security concerns and performance issues. To replace create_function(), you can use anonymous functions (also known as closures) as a more secure and efficient alternative.

php
// Using anonymous functions as a replacement for create_function()

$addition = function($a, $b) {
    return $a + $b;
};

echo $addition(2, 3); // Output: 5