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

Override With Interface

<?php

interface i {
    function foo();
}

class X implements i {
    #[Override]
    function foo() {}
}

var_dump(new x);

The override attribute checks that a method is actually overriding a parent definition of the same method: this implies that a class must have a parent to use the Override attribute.

There is a special case, which is a class without a parent, though implementing an interface. The Override attribute may be used on any of the interface method, though the class has no parent.

See Also

PHP Features

Last updated: 10 September 2026