News Feed
Sections




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

Shawn Stratton's Blog:
Accesors and Religion
May 17, 2011 @ 14:46:32

Shawn Stratton has a new post to his blog talking about a topic he calls "flame bait" - the use of accessors in PHP applications (getters and setters) to access class properties.

Objects have prop­er­ties which some­times need spe­cial logic on how they are retrieved and set. There are sev­eral solu­tions to this and every­body has a dif­fer­ent view point about which is cor­rect, none are pretty and all have draw­backs which range from writ­ing extra code, cre­at­ing some­thing that has poor exten­si­bil­ity, or has issues with con­sis­tency. These don't even breach the issues with IDE code com­ple­tion and analy­sis. Lets look at some of these solutions.

The solutions are the direct access to the class properties (which can cause some painful inconsistencies when things get complicated) and the alternative of setting up getters/setters for everything. Shawn's alternative makes use of the __get and __set magic methods to catch the property values being set and handle them correctly, developers being none the wiser.

0 comments voice your opinion now!
accessors opinion getter setter class property


blog comments powered by Disqus

Similar Posts

Phil Sturgeon's Blog: What happens next?

Indra Dutta's Blog: Top 5 reasons why PHP is a better choice than java & .NET for most websites

Stefan Koopmanschap's Blog: The PHP standards initiative

RawSEO Blog: 5 reasons why oscommerce is a nightmare

Padraic Brady's Blog: Nanosecond Scale Remote Timing Attacks On PHP Apps: Take Them Seriously?


Community Events





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


interview community conference threedevsandamaybe symfony laravel language zendserver voicesoftheelephpant series list tips podcast api code deployment release framework bugfix introduction

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