3v4l.org

run code in 300+ PHP versions simultaneously
<?php class B { public function __toString() { return 'b'; } } class A { function getFoo(): ?string { return new B(); } } $a = new A(); var_dump($a->getFoo());
Output for 8.1.16 - 8.1.30, 8.2.12 - 8.2.25, 8.3.0 - 8.3.14
string(1) "b"

preferences:
36.4 ms | 406 KiB | 5 Q