PHP5 - self referencing classes

This is a discussion on PHP5 - self referencing classes within the PHP General forums, part of the PHP Programming Forums category; Hi all, I have a class which creates a new object and caches this object (see source at the bottom). ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-28-2003
Thomas Hebinck
 
Posts: n/a
Default PHP5 - self referencing classes

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:48 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0