3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Its destructor brings the closure back to life by storing it in a global. class Resurrector { public $closure; public $self; public function __destruct() { $GLOBALS['resurrected'] = $this->closure; } } class Holder { public $castObject; public $resurrector; public $self; } $array = ['victim' => new stdClass(), 'key' => 'value']; $holder = new Holder(); $resurrector = new Resurrector(); // With only string keys, the cast object shares $array's hashtable. $holder->castObject = (object) $array; // The closure holds the same hashtable through its static vars. $resurrector->closure = function () use ($array) { return $array; }; // Self-references make both objects collectable only by the cycle collector. $holder->resurrector = $resurrector; $holder->self = $holder; $resurrector->self = $resurrector; unset($array); gc_collect_cycles(); unset($holder, $resurrector); gc_collect_cycles(); // Frees 'victim', though the resurrected closure still holds it. gc_collect_cycles(); // Reads the freed object. var_dump($resurrected()['victim']);
Output for 8.2.1 - 8.2.2, 8.2.4, 8.2.8 - 8.2.9, 8.2.13 - 8.2.16, 8.2.24 - 8.2.25, 8.2.28 - 8.2.29, 8.2.34, 8.3.4 - 8.3.6, 8.3.8 - 8.3.9, 8.3.12, 8.3.15 - 8.3.16, 8.3.19, 8.3.26, 8.3.30 - 8.3.35
object(stdClass)#1 (0) { }
Output for 8.2.0, 8.2.3, 8.2.5 - 8.2.7, 8.2.10 - 8.2.12, 8.2.17 - 8.2.22, 8.2.26, 8.2.31 - 8.2.33, 8.3.7, 8.3.11, 8.3.14, 8.3.17 - 8.3.18, 8.3.20, 8.3.22 - 8.3.25, 8.3.29
*RECURSION*
Output for 8.2.23, 8.2.27, 8.2.30, 8.3.0 - 8.3.3, 8.3.10, 8.3.13, 8.3.21, 8.3.27 - 8.3.28, 8.4.2 - 8.4.6, 8.4.9, 8.4.11, 8.4.13 - 8.4.15, 8.4.17 - 8.4.18, 8.4.20 - 8.4.22, 8.4.24 - 8.4.26, 8.5.4, 8.5.6 - 8.5.10

Process exited with code 139.
Output for 8.4.1, 8.4.7 - 8.4.8, 8.4.10, 8.4.12, 8.4.16, 8.4.19, 8.4.23, 8.5.0 - 8.5.3, 8.5.5, 8.5.11
zend_mm_heap corrupted
Process exited with code 134.

preferences:
65.48 ms | 1316 KiB | 85 Q