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

ReturnTypeWillChange Is For All

<?php

interface i {
    function foo(): int;
}

class x implements i {
    #[Returntypewillchange]
    function foo() : int { return 'abc'; }
}

ReturnTypeWillChange is an attribute that tells PHP that the return type of the related method is different from the defined by the PHP native methods. In fact, this attribute may also be used on custom interfaces, to skip the type checks.

The method signature must be compatible with the interface definition, but, with the attribute, it may actually return anything else. This also means that types may only be trusted after checking for attributes.

See Also

PHP Error Messages

PHP Features

Last updated: 10 September 2026