Created
November 7, 2014 14:27
-
-
Save fijiwebdesign/763702140e88db6611c5 to your computer and use it in GitHub Desktop.
PHP class delete itself
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Test | |
{ | |
public function delete() | |
{ | |
foreach($GLOBALS as $name => $value) { | |
if ($GLOBALS[$name] === $this) { | |
unset($GLOBALS[$name]); | |
} | |
} | |
} | |
} | |
$Test = new Test(); | |
var_dump($Test); | |
$Test->delete(); | |
var_dump($Test); // error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably not useful and only works for objects in global scope. Here for reference however.