Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any point to unset($this) in destructor?

Tags:

php

I came across one class and what cought my attention right away was this:

public function __destruct() {
        unset($this);
    }

My first thought was that this is just plain stupidity, it fact it looked so idiotic that I thought that either there really is a good reason to do this or the author is just clueless

Any thoughts? Any reasons to do this?

like image 989
Dmitri Avatar asked Nov 29 '22 03:11

Dmitri


2 Answers

Short answer: No

Long answer: Noooooooooooooooooooooo

like image 137
Peter Bailey Avatar answered Nov 30 '22 16:11

Peter Bailey


My first thought was that this is just plain stupidity, it fact it looked so idiotic that I thought that either there really is a good reason to do this or the author is just clueless.

The latter, I'm afraid: there is no point in unsetting an instance on destruct. It might be the original programmer is a big fan of being explicit, but the worst thing is that this doesn't even work:

<?php
class Foo {
    function __destruct( ) {
        unset( $this );
    }
}

$foo = new Foo;
$foo->__destruct( );
var_dump( $foo );
like image 38
Berry Langerak Avatar answered Nov 30 '22 17:11

Berry Langerak