Week 24, year 2014
- When to Use Static Methods - 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. [Mathias Verraes]
- Named Constructors in PHP - PHP allows only a single constructor per class. That’s rather annoying. We’ll probably never have proper constructor overloading in PHP, but we can at least enjoy some of the benefits. Let’s take a simple Time value object. Which is the best way of instantiating it? <?php$time=newTime("11:45");$time=newTime(11,45); The only correct answer is “it depends”. Both are correct from the point of view of the domain. [Mathias Verraes]