object oriented php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

object oriented php

Post by rajan »

from which php version object oriented is supported?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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..?
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

Post by rajan »

what is the enhancement in php 5.0? is it equal to j2ee.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP 5.1+ enhanced the OOP support more adding magic functions for isset(), conversion to string, among other things...
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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.
Post Reply