age; } } class Child extends Person{ } $child = new Child("aaa",5); $child->show(); ?> 为什么会打印出 aaa||5 子类不是应该继承了父类的show()方法,然后父类"/> age; } } class Child extends Person{ } $child = new Child("aaa",5); $child->show(); ?> 为什么会打印出 aaa||5 子类不是应该继承了父类的show()方法,然后父类">

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

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

WBOY
WBOYOriginal
2016-06-02 11:28:341168browse

对象php继承

class Person{
private $name;
private $age;

<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成员属性

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn