Skip to content

Instantly share code, notes, and snippets.

@mgsmus
Last active December 8, 2019 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgsmus/2c9a032aeb1c7921a9dc52333eb0c6d0 to your computer and use it in GitHub Desktop.
Save mgsmus/2c9a032aeb1c7921a9dc52333eb0c6d0 to your computer and use it in GitHub Desktop.
<?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