Covariance¶
Covariance allows a child’s method to return a more specific type than the return type of its parent’s method.
<?php
class v {}
class w extends v {
function foo() : w { }
}
class wv extends w {
// This method returns an object compatible with w, but more specific
function foo() : wv { }
}
?>
See also Type variance in PHP
Related : Contravariance
Added in PHP 7.4+