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

Freek Van der Herten:
Converting PHP 7 code to equivalent PHP 5 code
Apr 01, 2016 @ 14:50:56

Freek Van der Herten has a post to his site about another new library he's worked on (along with two others) to help convert PHP 7 code back to PHP 5 code - 7to5.

In the JavaScript world converting modern code to an older syntax is quite common. In the PHP world you don’t see that happen often. Symfony provides a few [polyfills](https://github.com/symfony/polyfill), but a full fledged conversion isn’t available. At the meetup of [our local PHP user group](http://www.meetup.com/phpantwerp/) [Jens Segers](https://twitter.com/jenssegers), [Hannes Van de Vreken](https://twitter.com/hannesvdvreken) and I were toying around with the idea of converting PHP 7 code to equivalent PHP 5 code automatically.

Today our little hobby project called 7to5 was tagged 1.0.0. You can view the repo on GitHub.

He starts by talking about what the library does to backport the code from PHP 7 to PHP 5 and how to install/use the command line tool. He then gets into things "behind the curtains" with a sample PHP 7 class and the resulting PHP 5 code. They made use of the PHP Parser tool for processing the PHP code provided. It does matching on certain element types and performs the token replacement. He gives examples of this with the null coalesce operator replacement and scalar type hinting.

tagged: convert php7 php5 code tool 7to5 introduction library

Link: https://murze.be/2016/03/converting-php-7-code-equivalent-php-5-code/


Trending Topics: