3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Cache{ protected function put($key,$value){ static $cache = []; var_dump($cache); return $cache[$key] = $value; } } $instance1 = new class extends Cache{ public function store($key,$value) { return $this->put($key,$value); } }; $instance1->store("one",1); $instance1->store("two",2); $instance1->store("three",3); $instance2 = new class extends Cache{ public function store($key,$value) { return $this->put($key,$value); } }; $instance2->store("four",4); $instance2->store("five",5); $instance3 = new class extends Cache{ public function store($key,$value) { return $this->put($key,$value); } }; $instance3->store("six",6); $instance3->store("seven",7);
Output for 8.1.9 - 8.1.28, 8.2.10 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
array(0) { } array(1) { ["one"]=> int(1) } array(2) { ["one"]=> int(1) ["two"]=> int(2) } array(3) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) } array(4) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) ["four"]=> int(4) } array(5) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) ["four"]=> int(4) ["five"]=> int(5) } array(6) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) ["four"]=> int(4) ["five"]=> int(5) ["six"]=> int(6) }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array(0) { } array(1) { ["one"]=> int(1) } array(2) { ["one"]=> int(1) ["two"]=> int(2) } array(3) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) } array(4) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) ["four"]=> int(4) } array(5) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) ["four"]=> int(4) ["five"]=> int(5) } array(6) { ["one"]=> int(1) ["two"]=> int(2) ["three"]=> int(3) ["four"]=> int(4) ["five"]=> int(5) ["six"]=> int(6) }
Output for 7.3.33, 7.4.26, 8.0.13 - 8.0.22
array(0) { } array(1) { ["one"]=> int(1) } array(2) { ["one"]=> int(1) ["two"]=> int(2) } array(0) { } array(1) { ["four"]=> int(4) } array(0) { } array(1) { ["six"]=> int(6) }

preferences:
86.01 ms | 402 KiB | 32 Q