3v4l.org

run code in 500+ PHP versions simultaneously
<?php class XABC { function foo() { // static does not apply to self $f = static function () : self { // __CLASS__ is preserved in the closure echo __CLASS__.PHP_EOL; return new self(); }; return $f; } } var_dump((new xabc)->foo()());
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.6
XABC object(XABC)#1 (0) { }

preferences:
39.69 ms | 848 KiB | 4 Q