Jump to content

Recommended Posts

Hi to all!

This is something that comes to my mind very often. Being a .NET and Java programmer I am very used to OOP and OO Best practices.

Now I am working with PHP and I always want to do things as I am used to, lots of classes and interfaces to be able to extend and scale.

So in my team we always have the same discussion. Is OOP in PHP penalize performance? If I want a really really fast website should I move to functions and arrays and let go OOP? Is that true for PHP?

 

Thanks,

 

Jonathan

Link to comment
https://forums.phpfreaks.com/topic/87402-classes-and-oop-penalize-performance/
Share on other sites

The short answer: yes. A small, well written procedural PHP application will typically perform better, simply because there's less overhead. Arrays are pretty damn fast, and variables of primitive types are typically less costly to create in any language.

 

In practice however, procedural applications quickly start to suffer from the lack of flexibility the procedural paradigm provides. It is easier to optimize a procedure when it's abstracted, instead of duplicated. To gain some flexibility and the ability to share data, procedural applications often rely on global data.

 

As an example, take a look at Drupal. Try dumping $GLOBALS and see the massive amount data that is kept in memory for the duration of a request.

That's what I think, but then it's really hard to convince people that the procedural paradigm will make things really hard to handle and eventually will become worse as soon as the business requirements start to change and you have to adapt your application. They always say that conventions and common sense will fix things.

Since classes brings overhead (even if small) it is a reason good enough for most of PHP developers to justify long and complicated functions, lots of global variables and weakly typed functions parameters using arrays, etc.

Do you really think it's possible to build a huge website that handles hundreds of thousands of requests each day using an object oriented approach in PHP?

Do you really think it's possible to build a huge website that handles hundreds of thousands of requests each day using an object oriented approach in PHP?

 

its possible but don't something you should be doing if you are starting out new and not with a large existing old code based.

its possible but don't something you should be doing if you are starting out new and not with a large existing old code based.

 

What do you mean by that? I didn't understand if I should or I shouldn't.

Old code based application can always be refactored and changed.

I believe my question was more oriented to the performance issues that you can introduce to a huge application with lots of pageviews just because you wanted an object oriented solution. Does it really affects the performance that much so PHP developers should avoid using the benefits of OOP? Any one with real life experience that want to share the knowledge?

Do you really think it's possible to build a huge website that handles hundreds of thousands of requests each day using an object oriented approach in PHP?

 

Of course. All PHP frameworks of mention use OO, including Zend's own Zend Framework and the official component repository, PEAR. Massive amounts of websites have been build using frameworks like ZF, Symfony or even CakePHP and CodeIgniter.

 

Anyone claiming that OO has no place in PHP is either ignorant or out of touch with the times, take your pick.

 

Before PHP 5.1, OO in PHP was indeed very slow, but this is no longer true.

What do you mean by that? I didn't understand if I should or I shouldn't.

Old code based application can always be refactored and changed.

I believe my question was more oriented to the performance issues that you can introduce to a huge application with lots of pageviews just because you wanted an object oriented solution. Does it really affects the performance that much so PHP developers should avoid using the benefits of OOP? Any one with real life experience that want to share the knowledge?

 

Your question seemed just if it could and just because you can refactor code, doe snot mean it is the best solution.  I mean the system I was working on was at least 500+ files of php code and 100+ or perl files with very little classes(maybe 4-5).  When you have that much procedural code, it is easier and quicker to start from scratch.

 

I have yet to find a reason not to use OOP.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.