如果我有以下内容:
abstract class AbstractSingleton
{
protected static $instance;
public static function & getInstance()
{
if(null === static::$instance) static::$instance = new static();
return static::$instance;
}
protected function __construct() { }
}
一个扩展类的用户能否重新定义 __construct
的可见性?
class Singleton extends AbstractSingleton
{
public function __construct() { } // That would be a problem
}
第二个问题是,如果在AbstractSingleton
中将__construct
定义为私有,那么对于子类会发生什么情况?是否根本没有构造函数?该类会提供一个新的默认构造函数吗?如果是,可见性是什么?