作者gpmm (银色)
看板PHP
标题Re: [讨论] 能不能这样判实体化成功与否?
时间Wed Sep 26 16:17:21 2012
※ 引述《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