(PHP 8 >= 8.3.0)
This attribute is used to indicate that a method is intended to override a method of a parent class or that it implements a method defined in an interface.
If no method with the same name exists in a parent class or in an implemented interface a compile-time error will be emitted.
<?php
class Base {
protected function foo(): void {}
}
final class Extended extends Base {
#[\Override]
protected function boo(): void {}
}
?>
Output of the above example in PHP 8.3 is similar to:
Fatal error: Extended::boo() has #[\Override] attribute, but no matching parent method exists
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant