[討論] 能不能這樣判實體化成功與否?
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';
}
在未加入__toString之前是會說could not be converted to string
加入之後是會說回應
toString() must return a string value
嗯..沒辦法在實體化時判斷是否有成功嗎?
還是真的要勤勞點加個屬性來判斷嗎?
(懶人病發作XD)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 112.104.145.107
→
09/26 15:05, , 1F
09/26 15:05, 1F
→
09/26 15:07, , 2F
09/26 15:07, 2F
→
09/26 15:07, , 3F
09/26 15:07, 3F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 4 篇):