Junior — Middle
Is it permissible to declare a method with a privacy modifier inside an interface?
sobes.tech AI
Answer from AI
In PHP, interfaces are intended for declaring public methods that must be implemented by classes. Declaring methods with a private modifier inside an interface is not allowed — all interface methods are public by default.
Attempting to declare a private method in an interface will result in an error.
An example of a correct interface:
interface Logger {
public function log(string $message);
}
If private logic is needed, it is implemented inside the class, and the interface only describes the public contract.