News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Bence Eros' Blog:
Getters, setters, performance
July 12, 2011 @ 11:39:18

Bence Eros has put together a new post to his blog looking at some of the results he's found from performance testing the use of getters and setters in PHP.

The usage of getter and setter methods instead of public attributes became very popular in the PHP community, and it's going to become the standard coding convention of so many PHP libraries and frameworks. On the other hand many developers - including me too - strongly unrecommend such convention, because of its performance overhead. I wanted to make some performance comparison for years, and today I had time to do that. In this post I would like to show what I found.

He starts with a question every developer asks as their working in their application - why and when should they use getters and setters for their classes. He talks about using them as primary functionality or as fallbacks only when needed. He includes the simple benchmarking script he used to compare accessing/setting public attributes directly and using a getter/setter to do the same. The results aren't very surprising if you think about the "magic" that has to happen for getters and setters to work. See the rest of the post for those numbers.

0 comments voice your opinion now!
getter setter performance benchmark compare magic


blog comments powered by Disqus

Similar Posts

PHPImpact Blog: PHP NetBeans IDE 6.1 is in the house!

Sebastian Bergmann\'s Blog: PHP 5.1 / GCC Benchmark (Update)

Kurt Payne's Blog: User register_tick_function to profile your code

Matt Knight's Blog: Optimising Zend_Config

Jani Hartikainen's Blog: Improving Ajax performance in Zend Framework applications


Community Events











Don't see your event here?
Let us know!


opinion introduction framework series application facebook hack symfony2 overview package composer code component unittest release security podcast hhvm language install

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework