3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public $v = "Not destructed"; public static $something = 0; public function __destruct() { print "A destructed\n"; $this->v = "descructed"; $this->x = new B(); A::$something++; B::$something++; C::$something++; } } class B { public $v = "Not destructed"; public static $something = 0; public function __destruct() { print "B destructed\n"; $this->v = "descructed"; $this->x = new C(); A::$something++; B::$something++; C::$something++; } } class C { public $v = "Not destructed"; public static $something = 0; public function __destruct() { print "C destructed\n"; $this->v = "descructed"; $this->x = new A(); A::$something++; B::$something++; C::$something++; } } function use_some_memory() { $a = "paul tarjan "; $as = []; $bs = []; $cs = []; while (count($as) < 10) { $a .= $a; $as[] = new A(); $bs[] = new B(); $cs[] = new C(); } // deliberate_OOM(); } function deliberate_OOM() { $a = "paul tarjan "; $as = []; $bs = []; $cs = []; while (true) { $a .= $a; $as[] = new A(); $bs[] = new B(); $cs[] = new C(); } } function on_shutdown() { print "A::something =" . A::$something . "\n"; print "B::something =" . B::$something . "\n"; print "C::something =" . C::$something . "\n"; } register_shutdown_function('on_shutdown'); $a = new A(); $b = new B(); $c = new C(); use_some_memory();

preferences:
37.37 ms | 402 KiB | 5 Q