How can PHP classes inherit constructors in a modular setup?

When using a modular setup in PHP, classes can inherit constructors by utilizing the parent::__construct() method within the child class constructor. This allows the child class to inherit the constructor functionality of the parent class, ensuring that any necessary setup or initialization is performed when an instance of the child class is created.

// Parent class with constructor
class ParentClass {
    public function __construct() {
        echo "Parent constructor called\n";
    }
}

// Child class inheriting constructor from ParentClass
class ChildClass extends ParentClass {
    public function __construct() {
        parent::__construct();
        echo "Child constructor called\n";
    }
}

// Create an instance of ChildClass
$child = new ChildClass();