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.31, 8.2.12 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
string(1) "b"

preferences:
69.04 ms | 406 KiB | 5 Q