Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


OOP in PHP - why not use it.

Posted on 2007-07-29
Medium Priority
Last Modified: 2008-02-01
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.

Question by:wildzero
LVL 35

Assisted Solution

Raynard7 earned 600 total points
ID: 19590166

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
LVL 10

Author Comment

ID: 19590179
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/

LVL 35

Expert Comment

ID: 19590191
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Accepted Solution

cg_medistox earned 700 total points
ID: 19590754
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.
LVL 17

Assisted Solution

psimation earned 700 total points
ID: 19590981
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.
LVL 10

Author Comment

ID: 19604198
Hi there,

Thanks for all the good replies!
I will be closing this off shorly, I think everything has been covered

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question