International PHP Conference Berlin 2025

The Override attribute

(PHP 8 >= 8.3.0)

Giriş

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.

Sınıf Sözdizimi

final class Override {
/* Yöntemler */
public __construct()
}

Örnekler

<?php

class Base {
protected function
foo(): void {}
}

final class
Extended extends Base {
#[
\Override]
protected function
boo(): void {}
}

?>

Yukarıdaki örneğin PHP 8.3 çıktısı şuna benzer:

Fatal error: Extended::boo() has #[\Override] attribute, but no matching parent method exists

Ayrıca Bakınız

İçindekiler

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top