Home  >  Article  >  Backend Development  >  新人学习PHP有关问题,发现书上代码不对

新人学习PHP有关问题,发现书上代码不对

WBOY
WBOYOriginal
2016-06-13 12:34:341031browse

新人学习PHP问题,发现书上代码不对
在书上发现一段代码,敲下来后发现不对。。

<br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<?php<br />
	class Person<br />
	{<br />
		private $name;<br />
		private $sex;<br />
		private $age;<br />
		<br />
		function __construct($name="",$sex="男",$age=23)<br />
		{<br />
			$this->name=$name;<br />
			$this->sex=$sex;<br />
			$this->age=$age;<br />
		}<br />
		function say()<br />
		{<br />
			echo "我的名字  ".$this->name.",性别  ".$this->sex.",年龄  ".$this->age."<br>";<br />
		}<br />
		function run()<br />
		{<br />
			echo $this->name."正在走路<br>";<br />
		}<br />
	}<br />
<br />
	class Student extends Person <br />
	{<br />
		var $school;<br />
		function study()<br />
		{<br />
			echo $this->name."正在".$this->school."学习<br>";<br />
		}<br />
	}<br />
	class Teacher extends Student <br />
	{<br />
		var $wage;<br />
		function teaching()<br />
		{<br />
			echo  $this->sex."正在".$this->school."教学,每个月工资为".$this->wage."<br>";<br />
		}<br />
	}<br />
	$teacher1=new Teacher("张三","男",40);<br />
	$teacher1->school="沈阳工学院";<br />
	$teacher1->wage=3000;<br />
	<br />
	$teacher1->say();<br />
	$teacher1->run();<br />
	$teacher1->teaching();<br />
?><br />

这里Teacher类中的teaching方法或不去不到$this->name。。书上却写可以获取的到,是我哪里写错了吗?

PHP?基础 继承
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