You are herePHP Passing By Value Killed The Singleton
PHP Passing By Value Killed The Singleton
It is a common misunderstanding of a singleton beeing a global variable expressed in OO style. This is not quite correct. Well, of course a singleton is global, but there's more: A singleton implements access control to the one and only instance of a class. That's why it's called singleton. But due to PHP's passing by value policy, this can easily be underminded.
$instance = new SingletonClass();
$a =& singleton();
However, every client can easily make a copy of the singleton instance, and therefore undermine what a singleton is for, ommiting the reference operator "&":
$a = singleton();
$b = singleton();
$a and $b now point to two different instances of SingletonClass, whom both are different to the singleton instance. Oops! A singleton indeed should prevent the user from doing this. And this, however, is impossible in PHP.