title: catch file I/O errors
body: <p>If I try to write to a file handle,</p>
  
  <pre><code>$ php5 -a
  Interactive mode enabled
  
  php &gt; $f = fopen('/dev/full','w+b');
  php &gt; var_dump(fwrite($f, 'lolcat'));
  int(0)
  php &gt;
  </code></pre>
  
  <p><code>fwrite()</code> returns 0, but doesn't tell for which reason the write failed.</p>
  
  <p>If I try to read from a file handle,</p>
  
  <pre><code>$ php5 -a
  Interactive mode enabled
  
  php &gt; $f = fopen('/proc/self/mem', 'rb');
  php &gt; var_dump(strlen(fread($f, 1000)));
  int(0)
  php &gt; var_dump(feof($f));
  bool(true)
  php &gt;
  </code></pre>
  
  <p>I can't even tell I/O errors from EOF.</p>
  
  <p>How can I fix this while supporting PHP 5.3 on every platform (at least *nix and WinNT) and still working with file handles as returned from <code>fopen()</code>?</p>