To demonstrate the value of covariance and why `static` alone is not
sufficient, here is a small example:
interface Enumerable extends \IteratorAggregate {
function getIterator(): Enumerator;
}
class Vector implements Enumerable, \ArrayAccess, \Countable {
function getIterator(): VectorEnumerator { /* … */ }
}
class VectorEnumerator implements Enumerator, \Countable {
/* … */
}
This shows why covariance is important for two reasons:
First, it shows that static isn't sufficient. The VectorEnumerator is
not the calling class, so self and static are not applicable.
Second, without covariance you could only declare a return type of
Enumerator for Vector::getIterator(); a calling class couldn't rely on
the properties of a VectorEnumerator that are unique to it, such as
\Countable.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php