ID:               34860
 Updated by:       [EMAIL PROTECTED]
 Reported By:      aaron-php at oakadaptive dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Linux (Red Hat and SUSE)
 PHP Version:      5.0.5
 New Comment:

The docs are clear about it:
"fwrite() returns the number of bytes written, or FALSE on error".

There were no error, but 0 bytes were written (because of the obvious
reason).


Previous Comments:
------------------------------------------------------------------------

[2005-10-13 21:04:53] aaron-php at oakadaptive dot com

Description:
------------
When fwrite can't write its whole second argument, it
returns the number of bytes it did succeed in writing
instead of false.

This behavior is mentioned in the user comments for fwrite,
but I couldn't find it reported as a bug.  I consider it a
bug, because it makes testing for a failed fwrite harder;
it's necessary to compare the length of the string with
fwrite's return value.

If it is intended behavior, I think the documentation should
be clearer, explicitly saying that if fwrite does return an
int, it can be less than the string's length (and as little
as zero).

(fwrite does return false if, for instance, its first
argument is not a file handle.  It also triggers a warning.)

Reproduce code:
---------------
$Filename = 'deleteme';
if (touch($Filename)): // Make sure file exists.
  $FileHnd = fopen($Filename, 'r'); // Open read-only.
  if ($FileHnd):
    $ByteCount = fwrite($FileHnd, 'test'); // Try to write 4 bytes.
    if ($ByteCount === false):
      echo "fwrite() returned false\n";
    else:
      echo "fwrite() wrote $ByteCount byte(s)\n"; // Reports
        // that 0 bytes were written (tested on v.  5.0.5 and 4.3.4):
    endif;
    fclose($FileHnd);
    unlink($Filename); // Clean up.
  endif;
endif;

Expected result:
----------------
fwrite() returned false

Actual result:
--------------
fwrite() wrote 0 byte(s)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=34860&edit=1

Reply via email to