What are some potential pitfalls when using fseek() in PHP?

One potential pitfall when using fseek() in PHP is not checking the return value of the function, which can lead to errors if the seek operation fails. To solve this issue, always check the return value of fseek() and handle any potential errors accordingly.

$file = fopen("example.txt", "r");

if ($file) {
    if (fseek($file, 0, SEEK_SET) === 0) {
        // fseek successful, continue with reading/writing operations
    } else {
        echo "Error seeking in file";
    }

    fclose($file);
} else {
    echo "Error opening file";
}