SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast laresistance2's Avatar
    Join Date
    May 2011
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The usefulness of destructive

    Hello,
    I want to know the real use constructors in PHP.
    I found some classes in PHP with a destructor that destroys all the attributes of objects in the destructor with unset
    Example:

    PHP Code:
    <?php
    class MyClass
    {

    private 
    $object1$object2$object3;

    public function 
    __construct()
    {
      
    $this->object1 = new ClassBB;
      
    $this->object2 = new SampleClass;
      
    $this->object3 = new Example;
    }


    // Content Class


    public function __destruct()
    {
      unset(
    $this->object1$this->object2$this->object3);
    }

    }
    Is that going it change something in performance of PHP?
    Otherwise what is the destructor in PHP?

    Thank you

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If those classes were taken up big chunk of memory and are no longer needed then unsetting them will most likely improve performance. I donít think there are other benefits.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's is completely unnecessary and make no difference.
    The objects that are instance variables are going to be picked up by GC as soon as the object itself is destroyed by GC.


Tags for this Thread

Bookmarks

Posting Permissions

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