Page 1 of 1

PHP 5's OOP vs PHP 4's

Posted: Thu Oct 04, 2007 5:29 pm
by figaro11
I went to php.net's documentation, to learn about classes and such, only to find that there two different documentations of Classes and Objects each for PHP 5 and 4.

Now I don't know which one to read. I know I have php 4 on my server with a php 5 interpreter. I could activate my php 5 interpreter on my site, but I don't want to mess up any current php scripts.

So what I'd like to know is what are the major differences in the Objects and Classes in php 5 and 4? Is there really a big change?

Posted: Thu Oct 04, 2007 6:25 pm
by Christopher
I would recommend trying PHP5 as there are usually few or no problems upgrading. PHP4 will no longer be supported.

I just upgraded a server that hosted many sites using PHP4. The process was pretty easy. In fact, PHP5 actually found a few bugs!. The main thing I found was that old SERVER vars had to be renamed. One of our members, Infolock, just wrote an article for php|architect about this I believe.

Posted: Thu Oct 04, 2007 10:20 pm
by superdezign
PHP4 isn't exactly "real" OOP, as it is missing a lot and is generally considered hackish. PHP5 is much more pure.

Posted: Thu Oct 04, 2007 11:40 pm
by figaro11
superdezign wrote:PHP4 isn't exactly "real" OOP, as it is missing a lot and is generally considered hackish. PHP5 is much more pure.
Okay. PHP 5 looks great. But what I'm concerned about is if I changed my php compiler over to php 5, what should I expect, error wise? What major differences are there between the two that might effect my current php scripts?

Posted: Fri Oct 05, 2007 1:21 am
by Stryks
I'm still really coming to grips with php5 oop, so I cant say I'm a really good judge of exactly what has changed.

I have however just switched a few classes made in php4 to a php5 environment, and had surprisingly few issues.

Actually, to be honest, I can only recall two problems (though each one numerous times).

Class variable definition changes from

Code: Select all

var $myClassVar;
to

Code: Select all

 public $myClassVar;
And creating instances by reference is depreciated. So

Code: Select all

$instance = &new myClass();
should be

Code: Select all

$instance = new myClass();
in php5, however the behavior is the same.

There were some minor issues elsewhere, but nothing specifically OOP related. I'm certainly not saying that other issues might not be present, I'm just saying these were the only real issues in my conversions. But then, my php4 classes were pretty basic.

Hope this helps