Skip to content

Instantly share code, notes, and snippets.

@fijiwebdesign
Created November 7, 2014 14:27
Show Gist options
  • Save fijiwebdesign/763702140e88db6611c5 to your computer and use it in GitHub Desktop.
Save fijiwebdesign/763702140e88db6611c5 to your computer and use it in GitHub Desktop.
PHP class delete itself
<?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
@fijiwebdesign
Copy link
Author

Probably not useful and only works for objects in global scope. Here for reference however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment