szeksu szeksu - 28 days ago 4x
PHP Question

PSR and constructor visibility

According to PSR-2

Visibility MUST be declared on all properties and methods

but what about
, it's specific function and I was wondering if it should also be marked by default as
when we're using


Yes you should also declare visibility for the __construct() method. In some cases the __construct is not public like

abstract class Singleton {

    private static $instances;

    final public static function getInstance() {
        $className = get_called_class();

        if(isset(self::$instances[$className]) == false) {
            self::$instances[$className] = new static();
        return self::$instances[$className];

    protected function  __construct() { }