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: 14 July 2026