Если я правильно понимаю, у вас есть что-то вроде:
class AbstractMyClass {
abstract protected function activate();
public function useItem() {
//...
$this->activate();
//...
}
}
class MyClass extends AbstractMyClass { /* ... */ }
В этом случае нет, невозможно вызвать разрушение объекта после вызова useItem
, если не считать:
$obj = new MyClass();
$obj->useItem();
unset($obj);
//if there are cyclic references, the object won't be destroyed except
//in PHP 5.3 if the garbage collector is called
Конечно, вы можете заключить разрушаемый объект в другой:
class MyClass extends AbstractMyClass { /* ... */ }
class MyWrapper {
private $inner;
public function __construct($object) {
$this->inner = $object;
}
public function useItem() {
if ($this->inner === null)
throw new InvalidStateException();
$this->inner->useItem();
$this->inner = null;
}
}
$obj = new MyWrapper(new MyClass());
$obj->useItem();