Created
August 14, 2014 08:30
-
-
Save Strate/ed2d5f1f5ef4685ea517 to your computer and use it in GitHub Desktop.
PHP refcount bug
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 | |
class B { | |
static public $instances = []; | |
public function __destruct() | |
{ | |
echo "Object B destructed!"; | |
} | |
} | |
$b = new B; // Here positive testing | |
B::$instances[spl_object_hash($b)] = &$b; | |
xdebug_debug_zval('b'); | |
echo "Expecting object destruction ... "; | |
$b = false; // Object destructed here as expected; | |
echo " Expectation finished\n"; | |
class A { | |
static public $instances = []; | |
public function __construct() | |
{ | |
self::$instances[spl_object_hash($this)] = &$this; | |
} | |
public function __destruct() | |
{ | |
echo "Object A destructed!"; | |
} | |
} | |
$a = new A; // Here negative testing | |
xdebug_debug_zval('a'); | |
echo " Expecting object destruction ... "; | |
gc_collect_cycles(); | |
$a = false; // Object is not destructed here. | |
echo " Expectation finished\n"; | |
echo "End of script\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment