PHP面向对象的继承

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<?php 	 
		class Person
		{
			function __construct($name, $sex)
			{
				$this->name = $name;
				$this->sex = $sex;
			}

			function showName()
			{
				echo $this->name;
			}

			function showSex()
			{
				echo $this->sex;
			}

		}

		/**
		* 子类
		*/
		class Teacher extends Person
		{
			
			function __construct($name, $sex, $job)
			{
				
				parent::__construct($name, $sex);
				$this->job = $job;
			}

			function showJob()
			{
				echo $this->job;

			}
		}

		//$p1 = new Person('刘一', '男');

		$laowang = new Teacher('老王', '男', '老师'); 
		// $p1->showSex();
		// $laowang->showJob();
		$laowang->showSex();
		$laowang->showName();
	?>
</body>
</html>

  

原文地址:https://www.cnblogs.com/zsongs/p/5304147.html