abstract class A { private $name; function __construct($param){ $this->name = 'liming'.'
'; } function getName() { echo $this->name; } // 调用子类中的方法getAge2 function getAge() { $this->getAge2(); } function getAge3() { return '23'; } }class B extends A { function getAge2(){ echo $this->getAge3(); }}$a = new B('a');$a->getName();$a->getAge();
Reply content:
abstract class A { private $name; function __construct($param){ $this->name = 'liming'.'
'; } function getName() { echo $this->name; } // 调用子类中的方法getAge2 function getAge() { $this->getAge2(); } function getAge3() { return '23'; } }class B extends A { function getAge2(){ echo $this->getAge3(); }}$a = new B('a');$a->getName();$a->getAge();
Mind-Set, why don't you (new A)->getAge()
try? Http://3v4l.org/cMZjE
PHP is a weakly typed language, which can be modulated by what 本身
type of object it is.
This is different from Java, where an object in Java can be tuned depending on what type of object it is pointing to. 引用