What are the benefits of using inheritance in OOP in PHP, and how does it contribute to code organization and scalability?

Using inheritance in OOP in PHP allows for code reusability, as it enables classes to inherit properties and methods from a parent class. This can lead to cleaner and more organized code by promoting a hierarchical structure. Inheritance also contributes to scalability by allowing for easier maintenance and extension of classes without having to duplicate code.

class Animal {
    public $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function eat() {
        echo $this->name . " is eating.";
    }
}

class Dog extends Animal {
    public function bark() {
        echo $this->name . " is barking.";
    }
}

$dog = new Dog("Buddy");
$dog->eat(); // Output: Buddy is eating.
$dog->bark(); // Output: Buddy is barking.