自己以为解释static 解释比较好的列子,希望大家,也能通过它来理解
public function myMethodA()
{
if(isset($this) && get_class($this) == __CLASS__)
return $this->myProp;
return 'C';
}
}
class B
{
public $myProp = 'B';
public function myMethodB()
{
$a = new A;
return $a->myMethodA().' ++++ '.A::myMethodA();
}
}
$b = new B();
echo $b->myMethodB(); // output: A ++++ C
// NOTE:
// if you don't verify "&& get_class($this) == __CLASS__"
// it will output A ++++ B, it seems that if a method is not marked as "static"
// its scope would be the scope in which the function was called
?>