Sobes.tech
Junior — Middle

Are you familiar with the concept of interfaces in programming?

sobes.tech AI

Answer from AI

In programming, an interface is a contract that defines a set of methods that a class must implement, but does not contain their implementation. In PHP, interfaces allow you to specify what methods a class should have, ensuring standardization and enabling polymorphism.

Example of an interface in PHP:

interface LoggerInterface {
    public function log(string $message);
}

class FileLogger implements LoggerInterface {
    public function log(string $message) {
        // implementation of logging to a file
        echo "Log to file: $message";
    }
}

Thus, any class implementing LoggerInterface will guaranteedly have a log method.