[請益] php中class的function

看板PHP作者 (ROLL)時間16年前 (2009/04/28 19:31), 編輯推噓3(306)
留言9則, 3人參與, 最新討論串1/2 (看更多)
以下有兩個function: function isTheLastSubproject($projectID) { $searchSub = "select * from Project where uppid='$projectID'"; $resultOfSearchSub = mysql_query($searchSub); if(mysql_num_rows($resultOfSearchSub) > 0) { return "false";//has child } else { return "true";//last child } } function get_subproject($projectID,$number) { echo $number.".".$projectID; if($this->isTheLastSubproject($projectID) == "false") { $str = "select * from Project where uppid='$projectID'"; $result = mysql_query($str); $number += 1; while($row = mysql_fetch_object($result)) { $this->get_subproject($row->pid,$number); } } else { echo "\t<br>"; } } 第一個function我本來是希望當做判斷 所以return true or false 但是我發現直接寫return true; 好像是錯誤的.... 正確的寫法為何啊? 我目前寫的return "true" 感覺只是回傳一個字串.... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.174.38.212

04/28 19:49, , 1F
引號之間 永遠是字串 ...
04/28 19:49, 1F

04/28 19:49, , 2F
return true; 就好
04/28 19:49, 2F

04/28 20:44, , 3F
再次強調 " 跟 ' 的分別,對於寫程式蠻重要的
04/28 20:44, 3F

04/28 20:44, , 4F
不只是 PHP 而已...
04/28 20:44, 4F

04/28 22:12, , 5F
我知道那是字串,是我直接寫return true;會錯誤耶...
04/28 22:12, 5F

04/28 22:14, , 6F
原本的判斷式為if(!this->isTheLast......)
04/28 22:14, 6F

04/29 01:26, , 7F
是 if($this -> isTheLast.....) .....
04/29 01:26, 7F

04/29 01:26, , 8F
if(!$this -> isTheLast.....)
04/29 01:26, 8F

04/29 01:28, , 9F
錯誤訊息是啥要看清楚呀 ~~ 至少也PO出來讓我們看 ..
04/29 01:28, 9F
文章代碼(AID): #19zkaUKT (PHP)
文章代碼(AID): #19zkaUKT (PHP)