Error de herencia de patrón de diseño de PHP Singleton
De php singleton clase a continuación
<?php
class Singleton
{
/**
* @var Singleton The reference to *Singleton* instance of this class
*/
private static $instance;
/**
* Returns the *Singleton* instance of this class.
*
* @return Singleton The *Singleton* instance.
*/
public static function getInstance()
{
if (null === static::$instance) {
static::$instance = new static();
}
return static::$instance;
}
/**
* Protected constructor to prevent creating a new instance of the
* *Singleton* via the `new` operator from outside of this class.
*/
protected function __construct()
{
}
}
Estoy tratando de heredar una nueva clase secundaria
class SingletonChild extends Singleton {
}
pero cuando hago pruebas
$obj = Singleton::getInstance();
$obj_two = SingletonChild::getInstance();
var_dump($obj === Singleton::getInstance()); // bool(true)
var_dump($obj === $obj_two); // false
Estoy recibiendo un error fatal de php.
Error fatal de PHP: Error no detectado: No se puede acceder a la propiedad SingletonChild :: $ instancia