Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
class TransparentSingleton {
private static $_instance = null;
private $_count = 0;
public function __construct() {
if (!isset(self::$_instance)) {
self::$_instance = $this;
}
}
public function setCount($count) {
self::$_instance->_count = $count;
}
public function getCount() {
return self::$_instance->_count;
}
}
$a = new TransparentSingleton();
$a->setCount(10);
$b = new TransparentSingleton();
echo $b->getCount(); //10
$b->setCount(5);
echo $a->getCount(); //5
I'm not sure it's all that useful; perhaps even terrible. But it does allow singletons to be used with things like PHP's Stream wrappers which take only a class name.