Interface Syntax
Interface methods are public by default and must not have a body. Interfaces can define constants but not properties.
Interface methods are public by default and must not have a body. Interfaces can define constants but not properties.
<?php
interface Logger {
// Constants are allowed
const DEFAULT_LEVEL = "info";
// Methods must be public, no body
public function log(string $level, string $message): void;
public function info(string $message): void;
public function error(string $message): void;
// Properties are NOT allowed in interfaces
// public string $prefix; // Fatal error!
}
Interface constants are inherited by implementing classes and can be accessed as ClassName::CONSTANT.