Skip to content

Instantly share code, notes, and snippets.

@ScreamingDev
Created December 16, 2012 08:08
Show Gist options
  • Save ScreamingDev/4304175 to your computer and use it in GitHub Desktop.
Save ScreamingDev/4304175 to your computer and use it in GitHub Desktop.
Deffered Statements solution with PHP
<?php
/**
* @author Mike Pretzlaw
* @link http://hallo-php-welt.de
* @copyright Mike Pretzlaw
*
* Example:
<?php
function foo() { $bar = "handle"; $unset = new Defer\Unset($bar); throw new Exception(); }
?>
*
* $unset will be deleted due to the scope and call it's destruct which unset the given variable.
*/
namespace Defer;
class Unset {
protected $_subject;
function __construct(&$stream)
{
$this->_subject = &$stream;
}
function __destruct()
{
$this->_subject = null;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment