When working with the singleton pattern. Is there any difference when holding the static instance in the class and holding it in the method that returns the instance?
Examples: Inside the class.
class cExampleA {
static $mInstance;
protected function __construct() {
/* Protected so only the class can instantiate. */
}
static public function GetInstance() {
return (is_object(self::$mInstance) ? self::$mInstance : self::$mInstance = new self());
}
}
Inside the returning method.
class cExampleB {
protected function __construct() {
/* Protected so only the class can instantiate. */
}
static public function GetInstance() {
static $smInstance;
return (is_object($smInstance) ? $smInstance : $smInstance = new self());
}
}
On a side note, the use of a ternary operator valid in the example (meaning could it cause problems) and is there any benefit/downfall to using is_object over isset?
Update: It seems that the only difference is that scope of the static instance?