Destructors
| From: | Jason Garber | Date: | Sun, 23 May 2004 21:48:57 +0000 |
| Subject: | Destructors | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-10056@lists.php.net to get a copy of this message | ||
Hello,
This is a question relating to the new PHP5 Object Destructor functionality. Consider the following:
<?php
class DB
{
function Query() { ... }
}
class Session
{
function SetVar() {
//sets a variable to be saved in the session} function __destruct() {
//Save session variables in database using global $oDB object.
global $oDB;
$oDB->Query(...);
}
}
$oDB = new DB();
$oSession = new Session();
$oSession->SetVar('foo', 'New Value');
//End of script
?>
Based on the above example, the $oSession->__destruct() method relies on the $oDB object still being usable. How can this be structured to ensure that the DB object does not get released first?
Thanks,
Jason
__________________________________________________________
Jason Garber
President & Chief Technology Officer
IonZoft, Inc.
814.742.8030 :: jason@ionzoft.com :: http://IonZoft.com
__________________________________________________________