<?php
interface FooInterface {
public function foo(FooInterface $foo);
}
class Bar implements FooInterface
{
public function foo(FooInterface $foo): FooInterface {
return new self();
}
}
$bar = new Bar();
$result = $bar->foo(new Bar());
var_dump($result);