What are the advantages of using an interface over an abstract class in PHP?

When deciding between using an interface or an abstract class in PHP, it's important to consider the differences between the two. Interfaces allow you to define a contract that classes must adhere to, without providing any implementation details. This promotes loose coupling and allows for greater flexibility in your codebase. On the other hand, abstract classes can provide some default implementations, but they limit the ability for a class to inherit from multiple sources.

<?php

// Using an interface
interface Logger {
    public function log($message);
}

class FileLogger implements Logger {
    public function log($message) {
        // Log message to a file
    }
}

class DatabaseLogger implements Logger {
    public function log($message) {
        // Log message to a database
    }
}

// Using an abstract class
abstract class AbstractLogger {
    public function log($message) {
        // Default log implementation
    }
}

class FileLogger extends AbstractLogger {
    // Specific file logging implementation
}

class DatabaseLogger extends AbstractLogger {
    // Specific database logging implementation
}