So I'm playing around with this Singleton pattern, and I ran into something that's messing me up.
I have objects that depend on Singleton pattern objects, so I define them like this:
Code: Select all
public function __construct()
{
$this->__pObject = CObject::GetInstance();
}
However, if the instance in CObject changes, $__pObject does not. I'm considering sending the instance as a reference, but before that, I want to know if this is possible at all:
Code: Select all
private function Preserve()
{
$this = self::$__instance;
}
I know it's not possible in the sense that I've written, but am curious as to whether or not there is a way to do this.