note 77919 added to language.oop5.decon
| From: | Typer85 at gmail dot com | Date: | Thu, 20 Sep 2007 00:32:53 +0000 |
| Subject: | note 77919 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130613@lists.php.net to get a copy of this message | ||
Some new programmers to PHP might not be familiar on how to manually call an object's
destructor at any time during a script's execution.
Let's assume I have the following class:
<?php
class Test
{
public function __destruct( ) {
echo 'Gone';
}
}
?>
Now let's assume I create ONE object of that class:
<?php
$Object = new Test( );
?>
The object exists throughout the duration of the script's execution. The destructor will be
called explicitly by PHP since PHP will automatically delete the object to clean up resources at the
end of the script's execution.
This is all fine and dandy, but now let's assume I create the object and than destroy it
manually:
<?php
$Object = new Test( );
// Delete Object.
unset( $Object);
?>
It is safe to assume that since only one object of that class exists and I manually destroyed it
that the destructor will be called only once when I destroy it and not when the script finishes
execution.
So in short, to manually call an object's destructor you use the unset( ) function.
----
Server IP: 69.147.83.197
Probable Submitter: 217.54.225.147
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/77919
Del: integrated -- https://master.php.net/note/delete/77919/integrated
Del: useless -- https://master.php.net/note/delete/77919/useless
Del: bad code -- https://master.php.net/note/delete/77919/bad+code
Del: spam -- https://master.php.net/note/delete/77919/spam
Del: non-english -- https://master.php.net/note/delete/77919/non-english
Del: in docs -- https://master.php.net/note/delete/77919/in+docs
Del: other reasons-- https://master.php.net/note/delete/77919
Reject -- https://master.php.net/note/reject/77919
Search -- https://master.php.net/manage/user-notes.php