Last active
December 8, 2019 19:10
-
-
Save mgsmus/2c9a032aeb1c7921a9dc52333eb0c6d0 to your computer and use it in GitHub Desktop.
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 MyClass { | |
public function __destruct() { | |
echo "Destroying object!\n"; | |
} | |
} | |
$o1 = new MyClass; | |
$r1 = new Weakref($o1); | |
if ($r1->valid()) { | |
echo "Object still exists!\n"; | |
var_dump($r1->get()); | |
} else { | |
echo "Object is dead!\n"; | |
} | |
unset($o1); | |
if ($r1->valid()) { | |
echo "Object still exists!\n"; | |
var_dump($r1->get()); | |
} else { | |
echo "Object is dead!\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment