class SomeClass
{
protected $_someMember;
public function __construct()
{
$this->_someMember = 1;
}
public static function getSomethingStatic()
{
return $this->_someMember * 5; // here's the catch
}
}
A: 静态方法不能访问 $this,因为静态方法可以在不实例化类的情况下执行。
接口和抽象类有什么区别? 接口定义了实现类 is 和调用接口的对象之间的契约。抽象类为将要扩展它的类预定义某些行为。在某种程度上,这也可以被视为一种契约,因为它保证了某些方法的存在。