How can the principles of Object-Oriented Programming (OOP) be effectively applied when creating a Page class in PHP?

When creating a Page class in PHP, we can effectively apply the principles of Object-Oriented Programming (OOP) by encapsulating the properties and methods related to a page within the class. This allows for better organization, reusability, and maintainability of code. Additionally, we can use inheritance to create specialized page classes that inherit common properties and methods from a base Page class.

class Page {
    private $title;
    private $content;

    public function __construct($title, $content) {
        $this->title = $title;
        $this->content = $content;
    }

    public function getTitle() {
        return $this->title;
    }

    public function getContent() {
        return $this->content;
    }
}

class HomePage extends Page {
    public function __construct($content) {
        parent::__construct("Home", $content);
    }
}

// Create a new HomePage object
$homePage = new HomePage("Welcome to our website!");
echo $homePage->getTitle(); // Output: Home
echo $homePage->getContent(); // Output: Welcome to our website!