title: fopen mode w+ and reading the file?
body: <p>I'm going through all the modes and trying to understand where can you apply some of them, and I stumbled upon <code>w</code>. Now I understand how that mode works, but what's the purpose of <code>w+</code>? Obviously if we use <code>fopen</code> right after opening the file, it won't work since the file will be truncated, so I assume it's good to write something in the file and then read from it later on, so I decided to test it like so:  </p>
  
  <pre><code>$handle = fopen('new.txt', 'w+');  
  fwrite($handle, '123');  
  $file = fread($handle, filesize('new.txt'));  
  var_dump($file);  // string '' (length=0)
  fclose($handle); 
  </code></pre>
  
  <p>For some reason it doesn't read the contains of the file later.<br>
  Could someone explain to me please where could it applicable, and what is wrong with my code? <code>filesize</code> returns 3, so it doesn't delete the contents of the file, I assume that the <code>$handle</code> might be used from the moment we opened the file and it doesn't update? Then it confuses me even more why would we use mode <code>w+</code> and doing reading from a file at the same time?<br>
  <strong>Edit:</strong> I can understand even how I can write something in the file with <code>r+</code> and then check what I've written with using <code>fopen</code> again, like so:  </p>
  
  <pre><code>$handle = fopen('new.txt', 'r+');  
  fwrite($handle, '123');   
  $handle = fopen('new.txt', 'r+');  
  $file = fread($handle, filesize('new.txt'));  
  var_dump($file);  
  fclose($handle);  
  </code></pre>
  
  <p>If I would do the same with <code>w+</code>, it would just delete the contents obviously, and I would not be able to read anything?</p>