<?php class A{ function __construct(){ $this->say(); $this->hello(); } protected function say(){ echo __CLASS__."[A]<br/>"; } private function hello(){ echo "[a]hello<br/>"; } } class B extends A{ function __construct(){ parent::__construct(); $this->say(); $this->hello(); } function say(){ echo __CLASS__."[B]<br/>"; } function hello(){ echo "[b]hello<br/>"; } } $a=new B(); ?>
output:
B[B]
[a]hello
B[B]
[b]hello
parent::__construct()执行时 say方法是子类的,而hello类是父类的,差异十分明显