What are the potential pitfalls of hardcoding paths within a PHP class?

Hardcoding paths within a PHP class can lead to issues when moving the code to a different server or directory structure. To avoid this, you can use predefined constants or configuration files to store paths, making your code more flexible and easier to maintain.

class Example {
    private $filePath;

    public function __construct() {
        $this->filePath = CONFIG_PATH . '/file.txt';
    }

    public function readFile() {
        $content = file_get_contents($this->filePath);
        return $content;
    }
}