News Feed
Sections




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

Mathias Verraes:
When to Use Static Methods
June 16, 2014 @ 10:20:52

Mathias Verraes has followed up his previous post about named constructors in PHP with a bit more clarification about when to use static methods (as he did in his "multiple constructor" examples previously).

Some of the reactions to my last blog post on Named Constructors in PHP, originate from the notion that static methods are inherently bad and should never be used. This is rather overgeneralized. Static methods are nothing more than namespaced global functions. Namespacing, I think we can all agree on, is great. As for global functions: We use those all the time. The native functions in PHP form our basic building blocks.

He talks about the main problem with their use, the shared global state, and compares it to a more stateful service. His solution is to either move to a normal object state (that allows for internal tracking) or think more about abstractions and how they relate.

0 comments voice your opinion now!
static methods opinion object stateless abstraction

Link: http://verraes.net/2014/06/when-to-use-static-methods-in-php/

blog comments powered by Disqus

Similar Posts

Java.Sys-con.com: Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?

Jani Hartikainen's Blog: You donít need a service layer: Fat controllers are okay

Stubbles Blog: Loading classes from the XP-Framework

Anthony Ferrara's Blog: To Comment Or Not To Comment - A Tale Of Two Stories

Anthony Ferrara: Being A Responsible Developer


Community Events

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


api community series development framework unittest threedevsandamaybe laravel5 podcast laravel voicesoftheelephpant feature language opinion library release introduction interview extension wordpress

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