Page 1 of 1

Lessons learned in migrating to PHP5?

Posted: Mon Jul 25, 2005 8:41 am
by nielsene
Has anyone here had success in migrating large legacy applications to PHP5? I'ld very much like to take advantage of the PHP5 features; my hoster can switch me to it at any time.

What's your recommended way to proceed?

From the development stand-point:
1) check out a new copy of my source from cvs
2) setup an alternate apache on a different local port
3) install php5, under custom name? (for command-line php scripts)
4) configure the alternate apache with php5

Thus I should have a standalone branch to play in, right?

How "pain-free" was your transition? I expect that most of the problems appear mid-transition? Ie, everything more or less works right away because of the general backward compatability, but things start failing as you find places that your object model wasn't as "good" as it should have been (ie perhaps a should have beeb private var was exposed, etc.

Any way of estimating the time to switch?

Re: Lessons learned in migrating to PHP5?

Posted: Mon Jul 25, 2005 8:54 am
by Roja
nielsene wrote:Has anyone here had success in migrating large legacy applications to PHP5?
Ooh! I did! I did!
nielsene wrote: How "pain-free" was your transition? I expect that most of the problems appear mid-transition? Ie, everything more or less works right away because of the general backward compatability, but things start failing as you find places that your object model wasn't as "good" as it should have been (ie perhaps a should have beeb private var was exposed, etc.

Any way of estimating the time to switch?
It depends entirely on what your code does, and what your expectations are.

First, if you expect *any* php4 code to be E_STRICT clean, you are setting yourself up for disappointment. The strict notices require changing your code to NOT work on php4 to pass. Even though I ALWAYS develop on E_ALL in php4, I turn off strict in php5. That will save you a headache.

Next, it depends on your code. If your code avoids passing-by-reference, object juggling, and the like, it will transition very well. My main game project (The Kabal Invasion / Blacknova Traders), was a breeze to transition. From 40,000 lines, I think I had to change a grand total of 100, and some of those were honestly BUGS that I hadn't noticed in php4.

However, that game is essentially a large pile of procedural code.. almost no classes, almost no OOP, piles of functions, and a not so pretty structure FULL of global variables. However, as a result, we almost never pass-by-reference, use objects, and thus avoided the few 'gotchas' for migrating.

As a general statement, most transitions to php5 are reasonable.

Re: Lessons learned in migrating to PHP5?

Posted: Mon Jul 25, 2005 10:38 am
by jmut
nielsene wrote:Has anyone here had success in migrating large legacy applications to PHP5? I'ld very much like to take advantage of the PHP5 features; my hoster can switch me to it at any time.

What's your recommended way to proceed?

From the development stand-point:
1) check out a new copy of my source from cvs
2) setup an alternate apache on a different local port
3) install php5, under custom name? (for command-line php scripts)
4) configure the alternate apache with php5

Thus I should have a standalone branch to play in, right?

How "pain-free" was your transition? I expect that most of the problems appear mid-transition? Ie, everything more or less works right away because of the general backward compatability, but things start failing as you find places that your object model wasn't as "good" as it should have been (ie perhaps a should have beeb private var was exposed, etc.

Any way of estimating the time to switch?
Hi,
You could try using my latest project.
http://securityscanner.sourceforge.net

I think it could come in handy....It is supposed to look for possible weak spots in the code.
But I also imported php4 - php5 compitability stuff.
For example if you've used array_merge() somewhere in your code (with variable called) it will just point out that both parameters should be arrays in php5 otherwise warnings will produce...

If you have any questions whatsoever feel free to ask.
P.S. The project is very basic for now but should run without a problem. Suggestions for improval are more than welcome.

Re: Lessons learned in migrating to PHP5?

Posted: Mon Jul 25, 2005 11:08 am
by nielsene
Roja wrote: First, if you expect *any* php4 code to be E_STRICT clean, you are setting yourself up for disappointment. The strict notices require changing your code to NOT work on php4 to pass. Even though I ALWAYS develop on E_ALL in php4, I turn off strict in php5. That will save you a headache.
Can you clue me in to some of the places where E_STRICT cause problems? I hate having code that doesn't make cleanly, so I'l probably want to work with E_STRICT on or would I be innudated with stupid messages?

Of course it one of those changes that once you start, you can't really go back. I'm a small niche application, while I'ld love to attract other developers, I haven't in 3 years... Changing to PHP5 would lessen the ability for others to be involved, but I think more real OO is worth it.....

Re: Lessons learned in migrating to PHP5?

Posted: Mon Jul 25, 2005 3:45 pm
by Roja
nielsene wrote:Can you clue me in to some of the places where E_STRICT cause problems?
I'm gonna punt on this one a little bit. I don't use it, so I haven't experienced it. I have however read about it on numerous sites. Here's a few links discussing it - again, if they aren't the best sources or explanations, I apologize.

http://derickrethans.nl/files/breaking.pdf (Start at page 13)

http://phplens.com/lens/lensforum/msgs.php?id=12411&x=1 - Issues in the adodb library under php5 with E_STRICT

http://www.phpinsider.com/smarty-forum/ ... php?t=5749 - Issues in smarty library under php5 with E_STRICT

The list goes on. Just google E_STRICT var public.. lots of hits.
nielsene wrote:I hate having code that doesn't make cleanly, so I'l probably want to work with E_STRICT on or would I be innudated with stupid messages?
That is precisely my understanding of the situation. Anytime you do:

var $whatever;

You end up with an error. Thats definitely a stupid message. The code works, is correct, and has no potential problems. It simply isn't the 'ideal' way to do it in php5. There were discussions on the php list about calling it E_PEDANTIC instead.. its that bad.
nielsene wrote:Of course it one of those changes that once you start, you can't really go back. I'm a small niche application, while I'ld love to attract other developers, I haven't in 3 years... Changing to PHP5 would lessen the ability for others to be involved, but I think more real OO is worth it.....
Thats an issue that lots of developers in multiple projects have been battling with. Few hosts offer php5 by default, which means less places it can run, and by extension, less people that can work with it.

As to the value of 'real' OO.. I'll leave that statement in quotes, and not comment. :)

Re: Lessons learned in migrating to PHP5?

Posted: Mon Jul 25, 2005 3:52 pm
by nielsene
Roja wrote:That is precisely my understanding of the situation. Anytime you do:

var $whatever;

You end up with an error. Thats definitely a stupid message. The code works, is correct, and has no potential problems. It simply isn't the 'ideal' way to do it in php5. There were discussions on the php list about calling it E_PEDANTIC instead.. its that bad.
Thanks for the lists of links. I feel IF I move to version 5, I would want to update all var's to the appropriate label, so at least thatt one feels "correct" to me. (And public/private is one of the biggeest things pushing me to version 5)