phpbackwards-compatibility

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()) { ...}

Solution

  • 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.