{if($this->getHdSize()<1024){echo "硬盤太小";return false;}return true;}為什么換成$hd=5000;之后,還是會返回“硬盤太小”呢?
{if($this->getHdSize()<1024){echo "硬盤太小";return false;}return true;}
{if($this->getHdSize()<1024){echo "硬盤太小";return false;}return true;}
2018-04-26
舉報
2018-05-02
謝謝,已經解決了,我是在getHdSize方法中使用的echo,應該是return。
2018-05-01
<?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();