Results 1 to 4 of 4

Thread: Destructor in PHP5

  1. #1
    Join Date
    Nov 2008
    Posts
    160

    Destructor in PHP5

    A small question about the destructor (__destruct ()) of a class in PHP5.

    Is it required to remove the attributes of the class in the destructor or does the mere fact that the object is destroyed, or unset () or at the end of the script enough to release, to. Similarly, data stored in its properties when executing the destructor?

    Are we obliged to do this:

    Code:
    <?php 
    class MyObject
    {
    private $myVar; 
    public function __construct() { }
    public function doIt() { }
    public function __destruct () 
    {
    / / Code or compulsory destruction of properties of the object made by implication? 
    unset($ this ->myVar);
    }
    }
    >

  2. #2
    Join Date
    May 2008
    Posts
    271

    Re: Destructor in PHP5

    The destructor in php to my knowledge has no value.

  3. #3
    Join Date
    May 2008
    Posts
    685

    Re: Destructor in PHP5

    I read in a book that was good for "close" files/sql connections. Except that I have ever own resources to a class. So, yes, I do not use to destruct

  4. #4
    Join Date
    May 2008
    Posts
    945

    Re: Destructor in PHP5

    Close the resources that are potentially useless (I do not know if PHP automatically closes all files at the end of a script for example, or all SQL connections)

Similar Threads

  1. Problem in LinkedList destructor.
    By KAIRU26 in forum Software Development
    Replies: 5
    Last Post: 15-02-2010, 06:14 PM
  2. What is the difference between a destructor and a finalizer?
    By Taylor D in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 09:47 AM
  3. Basic use of destructor
    By Sacchidananda in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 09:20 AM
  4. Abstract Classes in PHP5
    By nonose in forum Software Development
    Replies: 2
    Last Post: 16-06-2009, 02:33 PM
  5. Destructor in Java
    By Anti_Trend in forum Software Development
    Replies: 7
    Last Post: 25-10-2008, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •