看板 PHP 關於我們 聯絡資訊
※ 引述《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