Jump to content

Recommended Posts

I've been considering the whole question of OOP with respect to PHP and I was wondering if anyone can shed any light on how it affects performance.

 

My understanding, which is probably pretty limited, is that when a client makes a request to the PHP server, the server loads the page requested (plus any included files), parses and executes the code, and then gracefully closes the request and frees up any resources used in the request.

 

One of the (many) advantages of using objects is that it makes it easier to maintain state and share the values of the member variables between the member functions. However, if you look at it in terms of the model above, then this benefit is somewhat limited as state is not maintained between requests. This is a fundamental fact about programming with the web.

 

Also, since you don't want to have to work out which files to include on every page in terms of classes, then most people take the option of having one file list every class file and then just include that global class list. In any particular page request there are many classes you may not use and even many member functions you may not use in a class you do use in other ways. And I have noticed that there are a lot of people out there using classes in their PHP programming and many of these sites don't rate too well in terms of my performance.

 

So my question is, are my performance concerns founded? Is there a performance hit if we code many classes like this? Does PHP have a way of optimising the code out of the box without any extra add-ons? What are the real benefits of using classes in PHP (apart from the benefits of OOP in general)?

 

Pondering, pondering....

 

Link to comment
https://forums.phpfreaks.com/topic/114658-oop-php-and-performance/
Share on other sites

Also, since you don't want to have to work out which files to include on every page in terms of classes, then most people take the option of having one file list every class file and then just include that global class list. In any particular page request there are many classes you may not use and even many member functions you may not use in a class you do use in other ways. And I have noticed that there are a lot of people out there using classes in their PHP programming and many of these sites don't rate too well in terms of my performance.

 

This is not the case in PHP 5, which supplies the user with the __autoload() function (http://us3.php.net/manual/en/language.oop5.autoload.php).

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.