PHP VERSION: 8.2.18

type_hinting_return_type_subclass.php

<?php
// data type the return value

class MyClass
{
    public function 
foo($a): array
    {
        return 
$a;
    }
}

class 
MyOtherClass extends MyClass
{
    public function 
foo(): stdClass
    
{
        return new 
stdClass();
    }
}

Output