We have to move around 50+ Applications (small / large) to PHP 5.3 (from PHP 4.1). Does some has any experience with such an task?
- Time needed
- Tools
- Best setup for environment (Servers/Test?)
Does it make sense to move first to PHP 5.2? Is there any way to automatic detect applications using "PHP 4 Features" wich wont work in PHP 5?
I have no idea how to handle such an project. Thanks!
The most important thing to read would be the php.net section on migrating from PHP 4 to PHP 5. Since PHP 5 first came out, they have been moving towards a stricter language (PHP will be in strict mode by default in version 6), so you should expect to see a lot of warnings, if not errors.
There were more backward-compatibility-breaking changes made since PHP 5.0 came out, for completeness you should also read:
Migrating from PHP 5.0.x to PHP 5.1.x
Migrating from PHP 5.1.x to PHP 5.2.x
Migrating from PHP 5.2.x to PHP 5.3.x
I realise that's a lot of reading, but that should be a comprehensive list of everything that could break.
PHP_CompatInfo can help with a few checks for dependencies. PHP_CodeSniffer maybe with finding outdated constructs.
However, the differences between PHP versions are often gloryfied. Never had much problems with code relying on fringe cases. Unless of course this code still relies on long superglobals $HTTP_POST_VARS, then a few other gotchas are to be expected.
A helpful idiom to replace magic_quotes dependency for example is:
$_POST = array_map("mysql_real_escape_string", $_POST);
Because realistically most applications are never rewritten to use more contemporary database APIs.
First of all you should check php.ini settings, especially such as register_globals, magic_quotes_gpc - it can break the logic of your apps.
If you turn on error_reporting
and set it to E_ALL
then you should be able to see deprecated errors etc. I wouldn't bother targeting PHP5.2 and then 5.3.
Depends if you just want the apps to work or if you want to take advantage of new PHP features and performance improvements. If they just need to work then only fix the errors and ignore E_DEPRECATED
and E_NOTICE
warnings.
If the projects were written in a decent way to begin with then it should not be too hard to upgrade them.
That is not to say that it won't be a horribly boring and arduous job. It will also take far longer than you expect; particularly for 50 apps!
Turn off display_errors
, turn on log_errors
, set error_reporting
to -1
and look out for E_STRICT
and E_DEPRECATED
warnings.
This migration script (shameless plug) can help you with some of the deprecated things. It says 5.2 to 5.3 but may be useful for migrating from 4 too. And you can extend it (patches welcome :) for things you discover are frequently encountered.
PHPStorm IDE has pretty decent code analyzer which could point out some of the potential problems in your code. Give it a run through your app and see if it has something interesting to say. Also it will probably help you to find quickly the errors that may follow from using new keywords as function names, etc.
For your last question: IMHO you should go with 5.3, doing the job twice makes little sense.