Re: [RFC] Magic Method that handles unset($object)

From: Date: Sun, 10 Dec 2006 14:55:14 +0000
Subject: Re: [RFC] Magic Method that handles unset($object)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-26884@lists.php.net to get a copy of this message
Hi, Sebastian Bergmann wrote:
Is there another solution to this problem (apart from explicitly unsetting the $children array on the $parent object)?And even if there is I think that this method would be usefull.
You could use references, you would have to move some code around, though. I'm not sure that's exactly what you want, but give it a shot: class ParentC {
      public $children = array();
      public function __construct() {
          print "ParentC::__construct()\n";
      }
      public function __destruct() {
          print "ParentC::__destruct()\n";
      }
} class Child {
      public $parentO = null;
      public function __construct() {
          print "Child::__construct()\n";
      }
      public function __destruct() {
          print "Child::__destruct()\n";
      }
} function &setup() {
      $parent = new ParentC;
      $child = new Child;
      $parent->children[] = &$child;
      $child->parentO = &$parent;
      return $parent;
} $parent = &setup(); $parent = null; echo "--end--\n"; Result: ParentC::__construct() Child::__construct() ParentC::__destruct() Child::__destruct() --end-- -- Etienne Kneuss http://www.colder.ch colder@php.net Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal

« previous php.internals (#26884) next »