OOP in PHP - why not use it.

Hi there :-)

Looking maily at PHP 4 here, I know it's not the greatest OOP language in the world, but still people rave about it (and how it's better in PHP 5) yet lots of big scripts don't really use it. Like PHPBB etc, how come they did't write it like that.

Does anyone do it.

LVL 10
wildzeroAsked:
Who is Participating?
 
cg_medistoxCommented:
I find one piece of software the uses classes very well in PHP4 in Invision power boards.

The use of classes in his scripts was incredible.

I fully understand the comments that Raynard made about it not working very well but the guy who made Invision used classes to their full potential.

If you can get hold of an Invision script it is worth your time looking through it, i recently made an admin back end at the company i work for loosley based around the concepts he uses in his scripts.

PHP5 definately has more to work with in the way of classes though, i primarily come from a .net background that uses classes for just about everything so I can see there is a lot missing from PHP4.

I do though make sure i use classes for everything now, if i can see a real life situation in a program i am making then i will make a class for it because what may start off as a small project may grow to be quite large and then you will have a lot of code on your hands to change to make it more readable and to customise in the future.

I dont want any credit for this post because i am basically just going over what Raynard said, i just wanted to mention about Invision.
0
 
Raynard7Commented:
Hi,

Because PHP4 did not do it particularly well or efficiently then this is why generally installs for php4 do not use it,

because the syntax is different for php5 projects that are aimed at supporting most versions of php on most web servers will avoid it to minimize compatibility issues.

If you are developing for exclusively for php5 then oop is the way to go
0
 
wildzeroAuthor Commented:
Yea for sure, on local testing server has PHP 5 on it (as it is a real hassle to put PHP 4 on the newer Fedora Core) so looks like we are heading that way.

Also interesting is the site http://www.gophp5.org/


0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Raynard7Commented:
Also note that all the normal reasons for going OOP Apply, ie it is more scalable, it is easier to compartmentalize and to upgrade, and it is also easier to separate content generation and programming logic if you go down the OOP route
0
 
psimationCommented:
Procedural vs OO programming in PHP is a tightly "contested" debate, and it really boils down to a whole bunch of criteria.

Up intill PHP5, the way PHP handled classes was not considered to be "true" OO, since each instance of a class was actually a "copy" of the class, meaning that it was basically firstly not as efficient wrt memory usage, and secondly could cause unexpected "bugs" that were often very difficult to track ( due to the fact that overwriting a variable in a new instance did not change the class variable it was derived from.

PHP5 addressed this problem by having new instances of classes point to the memory address of the "original" class, and overwriting a variable in the derived class also changed the memory of the parent class.

Having said all that; I still frequently use procedural code even when working with PHP5. I find procedural code "reads" easier, especially in smaller application.

OO obviously has it advantages, specially due to re-usability and especially in larger application where more than one developer works on the same project.

In the end, there is really no "right or wrong' here. I'll go out o a limb and say that you can do anything in both styles of coding, in certain instances, OO will be an "overkill", while in others, procedural will take much more effort to do the same thing you did in OO.

That's what's nice about PHP, the choice is yours.
0
 
wildzeroAuthor Commented:
Hi there,

Thanks for all the good replies!
I will be closing this off shorly, I think everything has been covered
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.