Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting php 5.4 to 5.3

Is there any automation tool for converting a php 5.4 script back to 5.3? Mostly there are new style arrays causing problems.

This:

<?php
$x = [1, 2, 3];
$y = [
  'a' => [1,2],
  'b' => 'c',
];
function ff($x = []) { ...}

Should be converted to this:

<?php
$x = array(1, 2, 3);
$y = array(
  'a' => array(1,2),
  'b' => 'c',
);
function ff($x = array()) { ...}

Other backward compatibility issues are just a few and can be fixed by hand. I'm very bad at language processing, has anyone already done this? the converter doesn't need to be PHP. python, Java, ... are all file (I just prefer python, that's all).

like image 755
hkoosha Avatar asked Oct 21 '22 15:10

hkoosha


1 Answers

You can use a tool to convert your codebase from PHP 5.4+ to PHP 5.3, such as: http://github.com/endel/php-code-downgrade/

This tool will read all your files and rewrite code using PHP 5.3 standards, even for your composer dependencies.

The ideal scenario is to write code compatible with your production server, but sometimes it is not possible to know it by antecedence, so this tool may do the job for you.

The advantages of using this is that you can write modern code without worrying about legacy PHP version support.

like image 191
Endel Dreyer Avatar answered Oct 27 '22 00:10

Endel Dreyer