box icon indicating copy to clipboard operation
box copied to clipboard

Transpile you app from PHP7 to PHP5

Open theofidry opened this issue 6 years ago • 6 comments

Feature Request

It could be interesting to have a Box compactor which transpile the code from PHP7 to PHP5. As a result, for example, one could ship a PHP 7.2 app into a PHAR which would be compatible with PHP 5.4.

Some transpilers already exists, such as:

theofidry avatar Nov 21 '18 07:11 theofidry

This would be the next level.

nunomaduro avatar Nov 21 '18 08:11 nunomaduro

But why?

rask avatar Nov 21 '18 10:11 rask

@rask there is a number of CLI apps that by design should be compatible with low PHP targets, a few examples on top of my head: Composer, PHPBrew and Psysh.

In the case of those applications, having to stick with PHP 5.4 for example cripples the code-base, whereas a transpiler would allow to not abandon those lower versions whilst benefiting from the new PHP versions.

theofidry avatar Nov 21 '18 12:11 theofidry

I get the idea, but wouldn't this introduce issues with things like strict typehints, when transpiled to fully dynamic types (which rely on user input for instance)? The transpiler would need to generate type checking code on the fly to prevent issues like these.

rask avatar Nov 22 '18 09:11 rask

Indeed if you had guards but dropped them in favour of strict types & typehints you would loose something.

However I think that's an acceptable loss, at least for the first iteration. In my experience very few people were putting guards properly before so I don't think this will be a big issue, at least to most users

theofidry avatar Nov 22 '18 12:11 theofidry

Small update: no real progress on that front but now we do have Rector which allows to downgrade as well instead of upgrading. PHPStan does use it to some degree to add support for PHP 7.2.

theofidry avatar Feb 01 '23 08:02 theofidry