Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tomas Votruba:
Function create_function() is Deprecated in PHP 7.2 - How to Migrate?
Dec 18, 2018 @ 15:34:16

In this post to his site Tomas Votruba covers the create_function function, its deprecation in PHP 7.2 and how to refactor your code to remove it.

If there would be "Miss Deprecation of PHP 7.2", create_function() would definitely win. They can be very complex, tricky and very hard convert to PHP code. Moreover without tests.

Do you have over 5 create_function() pieces in your code? Let's see how to migrate them.

He starts by talking about why it's being deprecated (it's essentially an eval) and some examples of how it could be used to execute code. He then goes through several usage examples and shows how to refactor them into anonymous functions. In his examples he uses a mix of regular code conversions and a sort of hybrid using strings and code to replace the string (probably) used previously with create_function.

tagged: createfunction function deprecation anonymous tutorial refactor

Link: https://www.tomasvotruba.cz/blog/2018/12/17/function-create-function-is-deprecated-in-php-72-how-to-migrate/

Trending Topics: