protected修饰符修饰的成员在整个继承链上使用
protected修饰符修饰的成员在整个继承链上使用
Protected可以在整个继承链上被访问
示例代码:
class A() { protected $num =10; } class B extends A{ public function getNum() { echo $this->$num; } } $b = new B; $b->getNum(); //输出10
class A() { public function getNum() { echo $this->$num; } } class B extends A{ protected $num =10; } $b = new B; $b->getNum(); //输出10
上一篇:php逻辑运算符 短路运算符