当前位置:Gxlcms > PHP教程 > 对象-php继承的问题为什么能访问到父类的私有属性

对象-php继承的问题为什么能访问到父类的私有属性

时间:2021-07-01 10:21:17 帮助过:18人阅读

对象php继承

class Person{
private $name;
private $age;

  1. <code> public function __construct($name,$age){ $this->name = $name; $this->age = $age; } public function show(){ echo $this->name."||".$this->age; }}class Child extends Person{}$child = new Child("aaa",5);$child->show();</code>

?>

为什么会打印出 aaa||5

子类不是应该继承了父类的show()方法,然后父类方法中的$this不是应该指的是子类的对象实例吗
但是子类继承的时候应该没有继承到父类的private成员属性

所以为什么能打印出东西???

人气教程排行