3v4l.org

run code in 300+ PHP versions simultaneously
<?php class x { private static self $x; static function getInstance() { // all good return self::$x ??= new self(); } static function getInstance2() { // Not ok : cannot access before initialisation return self::$x = self::$x ?? new self(); } static function getError() { // Not ok : cannot access before initialisation if (!self::$x instanceof self) { self::$x = new self(); } return self::$x; } }
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3

preferences:
52.77 ms | 841 KiB | 4 Q