您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

一个对象怎么能new不成功

2024/3/8 21:42:55发布22次查看
一个对象如何能new不成功
类似这样:
class myclass {
private $index;
public function __construct($index) {
if ($index === 0) {
// 销毁对象
}
$this->index = $index;
}
public function getindex() {
return $this->index;
}
}
$t = new myclass(1);
echo $t->getindex(); // 正确返回
$t = new mycalss(0);
echo $t->getindex(); // 失败。

------解决思路----------------------
为什么要这样?还是要单例模式?
------解决思路----------------------
把$t对象销毁了,就没有引用了
------解决思路----------------------
私有化构造函数
------解决思路----------------------
单例模式试试呗
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product