Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Enforcing Return Type With Spl Classes

The types of the methods that were related to SPL were not validated against their interfaced. It was only enforced for other native or custom interfaces.

In PHP 8.1, it is now enforced.

PHP code

<?php

class X extends LimitIterator {
	function __construct() { echo __METHOD__; }
	public function current() {}
}

new X();

?>

Before

x::__construct

After

PHP Deprecated:  Return type of x::current() should either be compatible with IteratorIterator::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 IteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
x::__construct

PHP version change

This behavior changed in 8.1.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat