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

一个对象如何能new不成功

2025/11/19 3:28:51发布11次查看
类似这样:
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对象销毁了,就没有引用了
私有化构造函数
单例模式试试呗
找到了,直接在里边trigger_error了
该用户其它信息

VIP推荐

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