首页 >后端开发 >php教程 >新人学习PHP有关问题,发现书上代码不对

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-13 11:38:46834浏览

新人学习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?基础 继承
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn