News Feed
Sections




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

MaltBlue.com:
Do We Use Magic Methods or Not?
December 13, 2013 @ 10:39:20

In the latest post to his MaltBlue.com site Matthew Setter takes a look at magic methods. He tries to answer a few basic questions about them - are they worth using and can you truly test effectively when they're in use.

As a freelance Zend Framework developer, I'm always looking to improve the quality of the applications I produce. So over the last 6 - 12 months, I've been learning as much as possible about testing. During this time, I've found the way I code's dramatically changing (and improving). [...] In a recent development session, I attempted to test some of my ZendDb based classes, specifically the code which used the magic methods for dynamically building where clauses. [...] I can't speak for what it's like using PHPUnit's mock objects, as I always use Mockery instead. But after attempting to do so in Mockery, I hit a stumbling block when trying to test the chained call.

His example is a call to "lessThanOrEqualTo" to create his where clause that makes use of the "__get" magic method to get and return "Where" object. After some research (and conversations on IRC) he started wondering if the magic methods were worth the trouble they may cause during testing. He references this post and lists several of the comments made about their use, most of them not in favor.

0 comments voice your opinion now!
magic method zendframework sql builder query unittest testing

Link: http://www.maltblue.com/php/php-magic-methods-or-not

blog comments powered by Disqus

Similar Posts

Raphael Stolt's Blog: Zend Framework coding standards on one page

Zend Developer Zone: PHP Abstract Podcast Episode 13: Introduction to the Zend Framework

Jim Plush's Blog: Followup on rethinking Zend Models with DDD - Framework code included

Lee Blue's Blog: What's The Best PHP Framework?

Sebastian Bergmann's Blog: Distributed Testing with PHPUnit 3.1


Community Events





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


deployment podcast library laravel framework community api introduction language opinion release list series install voicesoftheelephpant bugfix package symfony tips interview

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