Home >Backend Development >PHP Tutorial >How Can I Replace PHP's Deprecated create_function() in PHP 7.2 ?
PHP 7.2's Deprecation of create_function()
The create_function() function is classified as deprecated in PHP 7.2.0. This article sheds light on this deprecation and provides guidance on rewriting code to accommodate this latest PHP version.
Rewriting Code to Replace create_function()
To adapt code that previously employed create_function() to PHP 7.2, consider adopting Anonymous Functions (known as Closures) in combination with the use keyword to access parent-scoped variables. A practical illustration:
$callbacks[$delimiter] = function($matches) use ($delimiter) { return $delimiter . strtolower($matches[1]); };
This code achieves the same functionality as the original create_function() implementation.
The above is the detailed content of How Can I Replace PHP's Deprecated create_function() in PHP 7.2 ?. For more information, please follow other related articles on the PHP Chinese website!