What are the best practices for debugging PHP code, especially when dealing with file manipulation?

When debugging PHP code that involves file manipulation, it is important to check for common issues such as file permissions, file paths, and proper error handling. Using functions like `file_exists()`, `is_readable()`, and `is_writable()` can help ensure the file is accessible. Additionally, utilizing `try-catch` blocks and error logging can help identify and troubleshoot any issues that may arise during file manipulation.

<?php
$file = 'example.txt';

try {
    if (file_exists($file) && is_readable($file) && is_writable($file)) {
        // Perform file manipulation operations here
    } else {
        throw new Exception('File is not accessible.');
    }
} catch (Exception $e) {
    error_log('Error: ' . $e->getMessage());
}
?>