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

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

WBOY
Release: 2016-06-13 11:38:46
Original
832 people have browsed it

新人学习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 />
Copy after login

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

PHP?基础 继承
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template