Re: [討論] 能不能這樣判實體化成功與否?

看板PHP作者 (銀色)時間11年前 (2012/09/26 16:17), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/4 (看更多)
※ 引述《JYHuang (夏天到了,冷不起來了說)》之銘言: : class test{ : public $boo; : public functoin __construct($bool){ : $this->bool = $bool; : return $bool; : } : public function __toString(){ : return $this->bool; : } : } : if ($bool = new test(true){ : echo 'it success'; : } 等等,我記得 construct 的 return 是沒有意義的, 因為它實際上 new class 只會丟回 object 啊… : 在未加入__toString之前是會說could not be converted to string : 加入之後是會說回應 : toString() must return a string value : 嗯..沒辦法在實體化時判斷是否有成功嗎? : 還是真的要勤勞點加個屬性來判斷嗎? : (懶人病發作XD) 其實看你的例子還是不很明白你要做什麼 o_Oa" 另外如果會有「實體化失敗」的情況那應該是直接噴 error 了吧? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 175.180.182.236
文章代碼(AID): #1GOheJNZ (PHP)
討論串 (同標題文章)
文章代碼(AID): #1GOheJNZ (PHP)