Page 1 of 1

object oriented php

Posted: Mon Dec 26, 2005 12:32 am
by rajan
from which php version object oriented is supported?

Posted: Mon Dec 26, 2005 12:38 am
by n00b Saibot
The proper nice feeling OOP started from 4.0.something although OOP existed in 3.0.26 AFAI remember. what version do you have for dev..?

Posted: Mon Dec 26, 2005 12:57 am
by rajan
what is the enhancement in php 5.0? is it equal to j2ee.

Posted: Mon Dec 26, 2005 1:21 am
by josh
In PHP 5 there is a new Object Model. PHP's handling of objects has been completely rewritten, allowing for better performance and more features.
every last detail is documented here
http://us3.php.net/manual/en/language.o ... #op5.intro

and for version 4 of php
http://us3.php.net/manual/en/language.oop.php

for one php5 allows visibility, a significant improvement over 4

Posted: Mon Dec 26, 2005 1:32 am
by m3mn0n
In PHP v3 OOP support was added with the addition of the Zend team to the project, and in every release since then it's been improved upon by Zend.

In PHP 4, the OOP model was similar to PHP 3 and it's argued that it was flawed. In PHP 5 however, the model was completely revamped and it has much more robust & extensive OOP support now.

If you've done OOP work in other languages, you'll pick up on the new PHP 5 OOP model easy.

Posted: Mon Dec 26, 2005 4:04 am
by rajan
In PHP 4, the OOP model was similar to PHP 3 and it's argued that it was flawed.
what is the best php4(procedual approach) or php4(object oriented approach) ?
if it is my compulsion to use php4

Posted: Mon Dec 26, 2005 5:11 am
by Jenk
There has been lengthy discussions, often getting heated, about this very subject.

The final conclusion is:

It's your choice. Whichever suits you and the requirements of the application in question.

Posted: Mon Dec 26, 2005 5:32 am
by m3mn0n
I'd recommend whatever you're more comfortable with.

If you like OOP programming, go for it, but learn PHP's OOP faults and limitations and work around them.

Posted: Mon Dec 26, 2005 8:24 am
by feyd
PHP 5.1+ enhanced the OOP support more adding magic functions for isset(), conversion to string, among other things...

Posted: Mon Dec 26, 2005 8:49 am
by josh
I would say use PHP5 so you're working with a more "real" OOP model. Also I think there's I think an error level in 5 called E_STRICT that will warn you about things like declaring class's variables without visibility, if for some reason this way of declaring variables is deprecated it's going to be more of a pain to upgrade all the legacy code. Even outside of OOP 5 has introduced a lot of new functions that when I used 4 often got frustrated were not available,
file_put_contents for one

I really like the way 5 is going and I think down the road when PHP grows and we get into new versions PHP5 legacy code will be a smoother transition into the newer versions then 4's


If you decide to go with PHP4, the decision really is yours like we already mentioned. In most of my applications I find myself encapsulating common code into classes but then using procedural code to instantiate / use their API. It all depends on your style of coding, the project, and how much you enjoy spaghetti code.