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());

preferences:
45.07 ms | 404 KiB | 5 Q