szeksu szeksu - 1 year ago 152
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

Answer Source

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() { }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download