{if($this->getHdSize()<1024){echo "硬盤(pán)太小";return false;}return true;}為什么換成$hd=5000;之后,還是會(huì)返回“硬盤(pán)太小”呢?
{if($this->getHdSize()<1024){echo "硬盤(pán)太小";return false;}return true;}
{if($this->getHdSize()<1024){echo "硬盤(pán)太小";return false;}return true;}
2018-04-26
舉報(bào)
2018-05-02
謝謝,已經(jīng)解決了,我是在getHdSize方法中使用的echo,應(yīng)該是return。
2018-05-01
<?php
class Computer{
??? public $cpu ="amd";
??? public $mainboard="華碩";
??? private $hd=5000;
??? public function game($gameName=''){
??????? if($this->getHdSize() <1024){
??????????? echo "硬盤(pán)太小";
??????????? return false;
??????? }return true;
??? }
??? public function job($work="工作"){
??????? echo ($this->game());
??? }
??? private function getHdSize(){
??????? return $this->hd;
??? }
}
$computer=new Computer();
$computer->job();