Last active
December 10, 2015 10:08
-
-
Save clemherreman/4418974 to your computer and use it in GitHub Desktop.
PHP unreferencing
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 | |
$a = new stdClass(); | |
$a->prop = 'objA'; | |
$b = new stdClass(); | |
$b->prop = 'objB'; | |
$c = array($a, $b); | |
echo 'before unsetting'.PHP_EOL; | |
array_map(function($obj) { | |
echo $obj->prop.PHP_EOL; | |
}, $c); | |
unset($b); | |
echo 'after unsetting'.PHP_EOL; | |
array_map(function($obj) { | |
echo $obj->prop.PHP_EOL; | |
}, $c); | |
// Output | |
clemherreman@macclem ~ $ php test.php | |
before unsetting | |
objA | |
objB | |
after unsetting | |
objA | |
objB // ObjB is still there because unset doesn't destroy an object, only a reference (here $b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment