3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Creation of dynamic property TestClass::$bb is deprecated in /in/hW7s7 on line 35 testArray: true Deprecated: Creation of dynamic property TestClass::$bb is deprecated in /in/hW7s7 on line 50 testObject: true Deprecated: Creation of dynamic property TestClass::$bb is deprecated in /in/hW7s7 on line 65 testSplFixedArray: true Deprecated: Creation of dynamic property TestClass::$bb is deprecated in /in/hW7s7 on line 80 testSplObjectStorage: true Deprecated: Creation of dynamic property TestClass::$bb is deprecated in /in/hW7s7 on line 94 testArrayObject: true Deprecated: Creation of dynamic property TestClass::$bb is deprecated in /in/hW7s7 on line 109 testSplDoublyLinkedList: true Deprecated: Creation of dynamic property TestClass::$bb is deprecated in /in/hW7s7 on line 124 testSplMaxHeap: true Deprecated: Creation of dynamic property TestClass::$bb is deprecated in /in/hW7s7 on line 139 testSplPriorityQueue: true
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
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.40
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

preferences:
371.33 ms | 402 KiB | 330 Q