{if($this->getHdSize()<1024){echo "硬盘太小";return false;}return true;}
谢谢,已经解决了,我是在getHdSize方法中使用的echo,应该是return。
<?php
class Computer{
public $cpu ="amd";
public $mainboard="华硕";
private $hd=5000;
public function game($gameName=''){
if($this->getHdSize() <1024){
echo "硬盘太小";
return false;
}return true;
}
public function job($work="工作"){
echo ($this->game());
}
private function getHdSize(){
return $this->hd;
}
}
$computer=new Computer();
$computer->job();