代码正常,为啥浏览器执行时,报警告: Notice: Undefined variable: fond in F:\Demo\class......

来源:4-1 对象继承-PHP面向对象编程

碧浪滔天

2017-04-18 11:30

<?php 
class Human{
		public $name;
		public $height;
		public $weight;
		public function eat($food){
			echo $this->name."'s eating".$fond."<br>";
		}
		
	}
	
	class NbaPlayer extends Human {
		
		public $team;
		public $playerNumber;
		
		function __construct($name,$height,$weight,$team,$playerNumber){
			
			//$this是php里面的伪变量,表示对象本身。
			//可以通过$this->的方式访问对象的属性和方法。
			$this->name = $name;
			$this->height = $height;
			$this->weight = $weight;
			$this->team = $team;
			$this->playerNumber = $playerNumber;
			
		} 
		
		public function run(){
			echo "Running\n";
		}
		
		public function jump(){
			echo "Jumping\n";
		}	
	}
	$player = new NbaPlayer("Jordan","198cm","98kg","BUll","23");
		
		echo $player->name."<br>";
		
		$player->eat("Apple");
		
?>

http://img.mukewang.com/58f588470001592106520191.jpg

写回答 关注

2回答

  • 戌戊戎戒
    2017-04-18 14:28:45
    已采纳

    看清楚你第七行是什么,应该是$food,不是$fond



  • 碧浪滔天
    2017-04-28 11:12:07

    哈哈,知道了

PHP面向对象编程

从容应对面试官的知识宝典,带你握面向对象的最重要的核心能力

70189 学习 · 368 问题

查看课程

相似问题