News Feed
Sections




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

Stubbles Blog:
Dependency Injection for static methods
November 08, 2010 @ 12:38:31

On the Stubbles blog today there's a new post from Frank Kleine showing how you can use a new feature of PHP 5.3 to perform dependency injection on static method - calling static methods with dynamic class names.

Developers who are familiar with the topic of clean code know that static methods are a problem, especially if it comes to testability. Static makes the code global, and if there is some kind of state involved it is even more a problem because this is global state then - both a maintenance and testability nightmare. [...] How can we keep our code clean and testable, at best without having a strongly coupled dependency to the class hosting the static method? Enter dependency injection for static methods.

He gives an example of how to use this to create a simple class that can change the name of the object an inner static function call is made to.

0 comments voice your opinion now!
dependency injection static method dynamic access


blog comments powered by Disqus

Similar Posts

Gonzalo Ayuso's Blog: Watermarks in our images with PHP and mod_rewrite

David Sklar's Blog: Runkit, "static", and inheritance

Kevin Schroeder's Blog: Handling ZF2 FQ Dependency Setter Injections

Alexander Netkachev's Blog: Controller/Action versus Folder/Page

Paul Jones: What Application Layer Does A DI Container Belong In?


Community Events





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


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

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