Enforcing Native PHP ReturnType
PHP did not enforce the return types in its own interfaces. Until PHP 8.1, incompatible signatures were allowed between them.
In PHP 8.1, such return type is now enforced. It should be set manually, or be temporarily suspended with the #[\ReturnTypeWillChange] attribute.
PHP code
<?php
class x implements iterator {
function __construct() { echo __METHOD__; }
public current() {}
}
new x;
?>
Before
x::__construct
After
PHP Deprecated: Return type of x::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Deprecated: Return type of x::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
x::__construct
PHP version change
This behavior was deprecated in 8.1.
This behavior changed in 9.0.