J-H*_*J-H 0 php protected superclass
一个小问题的简短问题.
class topclass {
protected $test;
//....
}
class childclass extends topclass {`
public static function accessVariable(){
//HOW CAN I ACCESS THE $Test VARIABLE OF THE SUPERCLASS HERE?
}...
Run Code Online (Sandbox Code Playgroud)
有人能帮助我吗?
非常提前
使用self::$test或parent::$test用于静态功能和$this->test常规功能.受保护的变量在扩展类的范围内可用,而私有变量则不可用.
使用self::$test和之间的区别在于parent::$test,如果您$test在子类中重写,则在使用时将获得重写的值self::$test.
当然,如果您希望静态访问该属性,则需要将其声明为静态(即protected static $test).