<?php

class foo
{
}
class qux
{
    public function foo() : foo
    {
        return $this;
    }
}
$qux = new qux();
$qux->foo();
<?php

class foo
{
}
class qux extends foo
{
    public function foo() : foo
    {
        return $this;
    }
}
$qux = new qux();
var_dump($qux->foo());