News Feed
Sections




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

Michael Kimsal's Blog:
magic __get and __set style?
December 21, 2010 @ 09:36:05

In this recent post to his blog Michael Kimsal asked about the usefulness of the __get and __set magic methods and the sort of code he usually sees along with it.

For a long time I've held that __get and __set in PHP were not all that hot - mostly because it's solely error handling. There's no way to deal invoke __get or __set behaviour for properties that are defined on a class. [...] For those who insist on using __get/__set, I *typically* see this [messyy] sort of style code. The effect is to cram a bunch of unrelated code in to the __get/__set overloading methods.

He suggests an alternative to the "cram it all in __get" approach - callbacks to other methods in the class to handle the different variable possibilities. In the comments there's other suggestions on how to get the same job done differently - mapping property values with __call, valid uses for getters/setters and a pointer to an internals discussion RFC about this same thing.

0 comments voice your opinion now!
getter setter oop class behavior opinion


blog comments powered by Disqus

Similar Posts

PHP -GTK Community Site: A New Trio of Posts (phpISO, a PHP-GTK book, and Dev Inspector)

PHPClasses.org Blog: Locating addresses on Google Maps embedded in PHP generated Web forms

DZone.com: How to remove getters and setters

DevShed: Handling Attachments in MIME Email with PHP

DevShed: Manipulating String Literals with Interpreter Classes in PHP 5


Community Events





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


podcast community configure api language laravel project introduction list library application wordpress bugfix framework code threedevsandamaybe series release interview developer

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