How are abstract classes and interfaces used in PHP to define class structures?

Abstract classes and interfaces are used in PHP to define class structures by providing a blueprint for other classes to inherit from. Abstract classes can have both abstract and concrete methods, allowing for some implementation details to be defined. Interfaces, on the other hand, only define method signatures that must be implemented by classes that implement the interface. This allows for a more flexible structure where classes can implement multiple interfaces but can only inherit from one abstract class.

// Abstract class example
abstract class Shape {
    abstract public function calculateArea();
}

class Circle extends Shape {
    public function calculateArea() {
        // Calculate area of a circle
    }
}

// Interface example
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
    }
}