在类方法和类中保持静态实例之间是否存在差异?

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?

Interesting question. In terms of behaviour, as far as I'm aware there is no difference at all between the two examples (other than scope).

PHP is a loosely typed programming language, so you could even omit the class property declaration all together in Example A. And with a loosely typed language there always seems to be more ways of achieving the same thing!

The real issue then soon becomes one of design pattern (data encapsulation in this case) to ensure we're writing code that follows a convention devised by people far smarter that I!

In this example, the Class should own its property and set the scope of that property appropriately (private in this case) and provide logical accessor methods.

Here's how I would write it:

class ExampleA
{
    static private $_instance = null;

    private function __construct(){}

    static public function getInstance()
    {
        if (!self::$_instance instanceof self) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
}

If you were to enclose the variable within the method itself, strictly speaking it wouldn't be a class property. Also, you lose a bit a legibility is a sense that other developers (not used to the design pattern of Example B) would be looking for a class property declaration, rather that digging through class methods.

Is there any difference when holding the static instance in the class and holding it in the method that returns the instance?

No, there's no difference in functionality, granted you modify the visibility of the static instance property to either protected or private:

class cExampleA {
    protected static $instance = null;
    // ...
}

Btw, don't use notations like $mInstance; nowadays you don't need those crutches

Also, seeing how you set the constructor to protected visibility, I'm assuming that you want to be able to extend the class later? In that case, you would need to change the getInstance() method:

public final static function GetInstance() 
{
    if (self::$instance === null) {
        self::$instance = new static;
    }
    return self::$instance;
}

Otherwise, your constructor should simply be private so that you can use new self; again.