What are the potential issues with using "r+" as the file mode when opening a file in PHP for reading and writing?

Using "r+" as the file mode when opening a file in PHP for reading and writing can potentially cause issues if the file does not already exist. To solve this, you can check if the file exists before opening it with "r+". If the file does not exist, you can create it by opening it with "w+" instead.

$filename = 'example.txt';

if (file_exists($filename)) {
    $file = fopen($filename, 'r+');
} else {
    $file = fopen($filename, 'w+');
}