PHP5 - self referencing classes

From: Date: Thu, 28 Aug 2003 14:48:40 +0000
Subject: PHP5 - self referencing classes
Groups: php.general 
Request: Send a blank email to php-general+get-161048@lists.php.net to get a copy of this message
Hi all, I have a class which creates a new object and caches this object (see source at the bottom). The new object holds a link on the creator class. The __descructor function of both classes are never called - because the classes are destroyed (killed), when the script terminates. Is there a way to "destruct" a class on another way manually? Does anyone know about any deeper documentation about objects in PHP5? Thanks! Bye, Thomas. - <?php class a { private $p_b; function __construct() { echo __CLASS__ . '::' . __FUNCTION__ . '<br>'; } function __destruct() { echo __CLASS__ . '::' . __FUNCTION__ . '<br>'; } function get_b() { if (!isset($this->b)) { $this->b=new b($this); } return $this->b; } } class b { private $p_caller; function __construct($caller) { echo __CLASS__ . '::' . __FUNCTION__ . '<br>'; $this->p_caller=$caller; } function __destruct() { echo __CLASS__ . '::' . __FUNCTION__ . '<br>'; } } $a=new a; $b=$a->get_b(); unset($a); unset($b); ?> Just prints: a::__construct b::__construct

« previous php.general (#161048) next »