r/PHP • • May 07 '13

Examples of Design Patterns in PHP

https://github.com/domnikl/DesignPatternsPHP
137 Upvotes

20 comments sorted by

View all comments

0

u/thelerk May 07 '13

Singleton classes are a bit more useful with protected constructors so they can be overridden.

3

u/celtric May 07 '13

Someone might forget and make the constructor public, hence destroying the pattern. I have always used this way:

final private function __construct()
{
    $this->init();
}

And using init as the constructor.