What are the drawbacks of manipulating derived classes to obtain file paths in PHP?

Manipulating derived classes to obtain file paths in PHP can lead to tightly coupled code, making it difficult to maintain and extend the application in the future. It violates the principle of encapsulation and can result in code that is hard to understand and debug. Instead, it's better to use a more flexible and modular approach, such as dependency injection, to handle file paths in PHP.

<?php
class FilePathProvider {
    protected $basePath;

    public function __construct($basePath) {
        $this->basePath = $basePath;
    }

    public function getFilePath($fileName) {
        return $this->basePath . '/' . $fileName;
    }
}

// Example usage
$filePathProvider = new FilePathProvider('/path/to/files');
$filePath = $filePathProvider->getFilePath('example.txt');
echo $filePath;
?>