How can a constructor be effectively utilized in an object-oriented PHP website?

Constructors in PHP can be effectively utilized in an object-oriented website to initialize object properties or perform tasks that need to be done when an object is created. By using constructors, you can ensure that certain operations are carried out automatically when an object is instantiated, reducing the need for manual initialization. This can help improve code readability and maintainability.

class User {
    private $username;

    public function __construct($username) {
        $this->username = $username;
        // Additional initialization tasks can be performed here
    }

    public function getUsername() {
        return $this->username;
    }
}

$user = new User("john_doe");
echo $user->getUsername(); // Output: john_doe