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!
Some of the syntax for classes has changed between PHP4 and PHP5 - for example, in PHP4, the constructor method was named the same as the class, whereas in PHP5, the constructor is named
__construct()
.PHP5 can still cope with PHP4-style class definitions, so your code is likely to still work, but you would nevertheless be well advised to change them to the new style, as there are a lot of features that you won't be able to use otherwise. In addition, of course, the old syntax will be removed eventually; your PHP4 classes will break in the future, so better to change them now rather than waiting till it's urgent.
Globals. You should already have been using
$_REQUEST
,$_POST
,$_GET
and$_COOKIES
in PHP4, a lot of older code may still be using the old style auto-globals that was standard ing PHP3. This is a massive security risk, so if you are still usingregister_globals
, you should start working on your code now to at least use$_REQUEST
instead for every place you've used an auto-global. This can actully be a very difficult task -- it can be hard to trawl through a large application trying to work out which variables are intended to be globals and which aren't, when there's nothing in the code to indicate one way or the other. Take it from someone who's had to do this, it can be a real nightmare. But this isn't something specific to moving to PHP5 -- as I said, even if you stick to PHP4, you really do need to deal with this issue. PHP5 doesn't change anything, except that theregister_globals
flag is now defaulted to being switched off, which may give you a bit more impetus to actually do this work.If you use any
ereg_
regex functions, these have been deprecated. You should replace them with the equivalentpreg_
functions. This isn't a big task, and in fact the functions are still available, so it can wait, as long as you're prepared to ignore the warnings telling you the function is deprecated. But again, as with the class syntax, it may be sensible to consider changing them now.Another feature that has changed, where the old syntax has been deprecated is passing-by-reference. In PHP4, we were encouraged to use the
&
character in the function call to pass variables by reference. In PHP5, the correct way of doing it is to put the&
character in the function declaration rather than where you call it. Again, the old syntax still works, but only if you can put up with PHP throwing warnings at you all over the place.