Created
December 16, 2012 08:08
-
-
Save ScreamingDev/4304175 to your computer and use it in GitHub Desktop.
Deffered Statements solution with PHP
This file contains 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 | |
/** | |
* @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