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了
