tags:

views:

441

answers:

4

What are some good steps to follow for a smooth migration from PHP4 to PHP5. What are some types of code that are likely to break?

+1  A: 

We had an app that relied heavily on the PHP 4 XML DOM functions and it required a lot of retooling to change over PHP 5.

Beyond that most changes were improvements to things like error handling (to take advantage of exceptions) and PHP Classes.

Mark Biek
+6  A: 

I also once worked on an app which used PHP4's XML support quite heavily, and would have required quite a bit of work to move toe PHP5.

One of the other significant changes I was looking at the time was the change of the default handling of function parameters. In PHP4 if I remember, they were pass-by-copy unless you specified otherwise, but in PHP5 is changed to pass-by-reference by default. In well written code, that probably won't make a big difference to you, but it could certainly cause problems.

I think one other thing I found changed is that objects are no longer allowed to overwrite their 'this' field. I would say that was a really bad idea to begin with (and I think it may have not been an intentional feature in PHP4), but I certainly found a few parts of our system that relied on it.

Hope some of that helps.

Matt Sheppard
+2  A: 

The best advice I could give anyone working with PHP4 is this:

error_reporting( E_ALL );

It pretty much will tell you exactly what you need to do.

Akira
Before or after migrating?
Rowland Shaw
+1  A: 

OOP is one of the largest differences. It won't break as the PHP4 and PHP5 OOP styles are interchangeable but I'd reccommend taking advantage of PHP5's new OOP styles. It's not a huge amount of work to convert your existing classes to PHP5 and it does give you some extra magical methods that may help solve some existing hacks (I remember having a near useless __toString equivalent method in most classes).

Ross