PHP头条
热点:

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


对象php继承

class Person{
private $name;
private $age;

    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();

?>

为什么会打印出 aaa||5

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

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

www.phpzy.comtrue/phpyy/4279.htmlTechArticle对象-php继承的问题为什么能访问到父类的私有属性 对象php继承 class Person{ private $name; private $age; public function __construct($name,$age){ $this->name = $name; $this->age = $age; } public function show(){ echo $...

相关文章

相关频道:

PHP之友评论

今天推荐