PHP5 Class destructors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dashifen
Forum Commoner
Posts: 35
Joined: Thu Feb 05, 2004 9:53 pm
Location: Champaign - Urbana, IL

PHP5 Class destructors

Post by dashifen »

Are class destructors called when the user navigates away from a page requiring a class? For example:

Code: Select all

class foo {
  function __construct() {
    // do important stuff
  }

  function __destruct() {
     // do other important stuff
  }

  // other functions
}

Code: Select all

<?
require_once("foo.php");
bar = new foo;
?>

<!-- HTML goes here using powers of foo -->
since that "page" requires the class foo to work, will the instance of foo on the page (named bar) be "destructed" when the user navigates away from the page? When the php code is parsed? When?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the class is destructed, likely, as soon as the page ends processing unless you've set it up in shared memory (probably)..
dashifen
Forum Commoner
Posts: 35
Joined: Thu Feb 05, 2004 9:53 pm
Location: Champaign - Urbana, IL

Post by dashifen »

That would certainly do what I needed it to.
Post Reply