eagleprof Posted July 14, 2008 Share Posted July 14, 2008 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.... Quote Link to comment https://forums.phpfreaks.com/topic/114658-oop-php-and-performance/ Share on other sites More sharing options...
KevinM1 Posted July 14, 2008 Share Posted July 14, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/114658-oop-php-and-performance/#findComment-589625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.