What are the best practices for handling file paths in PHP to ensure portability and flexibility?

When working with file paths in PHP, it's important to ensure portability and flexibility by using built-in functions like `realpath()` and `DIRECTORY_SEPARATOR` to handle paths in a platform-independent way. Additionally, using constants like `__DIR__` or `__FILE__` can help create relative paths that are consistent across different environments.

// Example of handling file paths in a portable and flexible way
$path = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'example.txt');
echo $path;