3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class TestClass { public function __destruct() { App::$flg = true; } } class App { public static $flg = false; public static function main() { $methods = array_filter( (new \ReflectionClass(__CLASS__))->getMethods(), function (\ReflectionMethod $r) { return preg_match('/^test/', $r->getName()); } ); array_walk($methods, function (\ReflectionMethod $r) { $r->invoke(null, null); }); } public static function testArray() { self::$flg = false; call_user_func(function () { $aa = new TestClass(); $bb = array($aa); $aa->bb = $bb; }); gc_collect_cycles(); printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true)); } public static function testObject() { self::$flg = false; call_user_func(function () { $aa = new TestClass(); $bb = new \stdClass(); $bb->aa = $aa; $aa->bb = $bb; }); gc_collect_cycles(); printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true)); } public static function testSplFixedArray() { self::$flg = false; call_user_func(function () { $aa = new TestClass(); $bb = new \SplFixedArray(1); $bb[0] = $aa; $aa->bb = $bb; }); gc_collect_cycles(); printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true)); } public static function testSplObjectStorage() { self::$flg = false; call_user_func(function () { $aa = new TestClass(); $bb = new \SplObjectStorage(); $bb->attach($aa); $aa->bb = $bb; }); gc_collect_cycles(); printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true)); } public static function testArrayObject() { self::$flg = false; call_user_func(function () { $aa = new TestClass(); $bb = new \ArrayObject([$aa]); $aa->bb = $bb; }); gc_collect_cycles(); printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true)); } public static function testSplDoublyLinkedList() { self::$flg = false; call_user_func(function () { $aa = new TestClass(); $bb = new \SplDoublyLinkedList(); $bb->push($aa); $aa->bb = $bb; }); gc_collect_cycles(); printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true)); } public static function testSplMaxHeap() { self::$flg = false; call_user_func(function () { $aa = new TestClass(); $bb = new \SplMaxHeap(); $bb->insert($aa); $aa->bb = $bb; }); gc_collect_cycles(); printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true)); } public static function testSplPriorityQueue() { self::$flg = false; call_user_func(function () { $aa = new TestClass(); $bb = new \SplPriorityQueue(); $bb->insert($aa, 1); $aa->bb = $bb; }); gc_collect_cycles(); printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true)); } } App::main();
Output for 7.0.0 - 7.2.0
testArray: true testObject: true testSplFixedArray: true testSplObjectStorage: true testArrayObject: true testSplDoublyLinkedList: true testSplMaxHeap: true testSplPriorityQueue: true
Output for 5.5.37 - 5.5.38, 5.6.23 - 5.6.28
testArray: true testObject: true testSplFixedArray: true testSplObjectStorage: true testArrayObject: true testSplDoublyLinkedList: false testSplMaxHeap: false testSplPriorityQueue: false
Output for 5.5.0 - 5.5.36, 5.6.0 - 5.6.22
testArray: true testObject: true testSplFixedArray: true testSplObjectStorage: true testArrayObject: false testSplDoublyLinkedList: false testSplMaxHeap: false testSplPriorityQueue: false