3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private function &getState(): array { static $state = ['counter' => 0]; return $state; } public function count(): int { return $this->getState()['counter']++; } } $x = new Foo(); $y = new Foo(); var_dump($x->count(), $y->count());;
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
int(0) int(1)

preferences:
52.49 ms | 406 KiB | 5 Q