Zend Developer Zone
Where the ElePHPants come to learn

Zend Developer Zone

5.2 to 5.3 migration

Incredibly Old Content Warning!

The content you are viewing is more than three years old. It is here for archival purposes. Do not use any advice in this article.

::Jedi Hand Wave:: This is not the information you are looking for. Move along.


The new release of PHP 5.3 brought many important additions and changes to PHP. Although longly awaited, some of the changes are not backwards compatible. Thus, code that worked fine with 5.2 may produce warnings or fail in 5.3.

Quick research shows that most prominent applications had to be patched or changed, even though minimally, to work cleanly with 5.3. To help people to convert their web applications to 5.3, I present here a migration script that would allow you to inspect your applications for potential migration problems.
Do not expect supernatural wonders from it, but it may save you some valuable time.

Here's what it can do:

  • catch wrong definitions of __magic methods
  • catch identifier conflicts with newly defined keywords (goto, namespace)
  • catch use of deprecated functions and recommend replacement

Here's what it can't:

  • detect messy use of references
  • detect problems related to changes in function signatures
  • fix the problems for you 😉

The script is very simple in use – just run php migrate.php myscript.php or php migrate.php directory/ and see if you'll get any warnings. If you get none, the script thinks your code is ok :) Running php migrate.php -h displays help.

I have placed the script on github – http://github.com/smalyshev/migrate
If you have any additions or suggestions for the script please comment or contact me directly.

Here’s an example of what it does:

<?php
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
    echo "$regs[3].$regs[2].$regs[1]";
} else {
    echo "Invalid date format: $date";
}

would produce this warning:

WARNING: Function 'ereg' is deprecated, please use 'preg_match' instead in file test.php line 2

And this code:

<?php
class Foo {
    static function __get()
    {
    	
    }
    
    static protected function __set()
    {
    	
    }
}


leads to:

WARNING: Magic method __get can not be declared as static in file test.php line 3
WARNING: Magic method __set can not be declared as static in file test.php line 8
WARNING: Magic method __set should be declared as public in file test.php line 8