News Feed
Sections




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

Reddit.com:
Avoid static methods at all costs? (testability)
September 26, 2012 @ 11:59:04

On Reddit.com there's a recent post questioning the (recently) common saying that PHP developers should avoid static methods when concerned about testability:

I get it: testing is important, and building your codebase in a manner that is easy to test should be a priority. However, sometimes I feel like I have to compromise on the elegance of my code in order to maintain testability. Cases where perhaps a static method makes sense, but end up having to perform some coding acrobatics in order to avoid it. Is this a common challenge, something many developers face and must balance between? Or am I misguided in how frequently static methods can be the most elegant solution (before taking testability into consideration)?

Answers point out a few things - that sometimes, state doesn't matter and static is okay or that they can be used if the instance they return is always exactly the same, never altered.

0 comments voice your opinion now!
static methods unittest testability opinion


blog comments powered by Disqus

Similar Posts

Strattonbrazil's Blog: php to python: Why PHP is now dead to me

Dutch Web Alliance: The definitive remote debug and unittest with PHPStorm guide: part 4

Pim Elshoff's Blog: In favour of typing

Padraic Brady's Blog: Mutation Testing Brain Dump

Olek Janiszewski's Blog: Autotest-like PHPUnit runner for a Zend Framework application


Community Events





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


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

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