What are the best practices for handling file operations in PHP functions?

When handling file operations in PHP functions, it is important to ensure proper error handling, file existence checks, and proper file permissions. It is also recommended to use absolute file paths to avoid any path traversal vulnerabilities.

function readFromFile($file_path) {
    if (file_exists($file_path) && is_readable($file_path)) {
        $file_contents = file_get_contents($file_path);
        return $file_contents;
    } else {
        throw new Exception('Unable to read file');
    }
}