How can object-oriented programming in PHP help with modular development and maintenance of code?

Object-oriented programming in PHP can help with modular development and maintenance of code by allowing developers to encapsulate data and behavior into objects that can be easily reused and extended. This approach promotes code reusability, makes it easier to maintain and update code, and helps in organizing complex systems into manageable modules.

// Example of using object-oriented programming in PHP for modular development

class User {
    private $name;
    private $email;

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

    public function getName() {
        return $this->name;
    }

    public function getEmail() {
        return $this->email;
    }
}

$user1 = new User("John Doe", "john.doe@example.com");
echo $user1->getName(); // Output: John Doe
echo $user1->getEmail(); // Output: john.doe@example.com