作者JYHuang (夏天到了,冷不起来了说)
看板PHP
标题[讨论] 能不能这样判实体化成功与否?
时间Wed Sep 26 14:59:34 2012
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
1F:→ buganini:好像少了个) =好像应该是==? __toString里面return ""呢? 09/26 15:05
2F:→ buganini:照理说__toString应该不是必要,可能有那个动作触发了 09/26 15:07
3F:→ buganini:把instance转型成字串的动作 09/26 15:07