php 类继承知识

<?php 
class Person{
	public function __construct(){
		return $this->run();
	}
}

class Me extends Person{

	public function run(){
		echo "I'm running";
	}

	public function jump(){
		$pass = "悄悄跳";
	}
}
$me = new Me(); # 为父类与子类的融合,
$me->jump();

# 输出:I'm running
<?php 
class Person{
	public function __construct(){
		return 'Person<br/>';
	}
}

class Me extends Person{
	public function __construct(){
		$parent = parent::__construct();
		return $parent.' Me <br/>';
	}
}
$me = new Me();
$res = $me->__construct();
echo $res;

# 输出:Person
#      Me   
# 实例化后调用方法,子类覆盖父类 
# 同时子类中parent::__construct()依旧具有意义

猜你喜欢

转载自blog.csdn.net/qq_30923243/article/details/86652536