php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51006 bug in fwrite section of the manual
Submitted: 2010-02-10 23:31 UTC Modified: 2010-02-16 07:32 UTC
From: php at mi dot cx Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at mi dot cx
New email:
PHP Version: OS:

 

 [2010-02-10 23:31 UTC] php at mi dot cx
Description:
------------
I suspect that the demo fwrite_stream(..) example contains a tiny buglet...

in:

function fwrite_stream($fp, $string) {
    for ($written = 0; $written < strlen($string); $written += $fwrite) {
        $fwrite = fwrite($fp, substr($string, $written));
        if (!$fwrite) {
            return $fwrite;
        }
    }
    return $written;
}

the snipet:

 if (!$fwrite) {
            return $fwrite;
        }

should read:

 if (!$fwrite) {
            return $written;
        }

Since if the write fails on the second iteration, it should return what has been written so far, not zero. Also, another improvement is probably:

 if ($fwrite===false) {
            return $fwritten;
        }

But not strictly necessary in this instance because the loop wont be entered if there is nothing to be written.

Chris Hale.

Reproduce code:
---------------
---
From manual page: function.fwrite
---



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-16 07:32 UTC] svn@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=295141
Log: Fixed bug #51006 (bug in fwrite section of the manual)
 [2010-02-16 07:32 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I agreed that the return value here seems odd, even though it might be intended to return false in case of a writing error. I changed it to return the value of $written.
 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=fa4a06c39e532f632753d9fe5c2138cc72ffbb47
Log: Fixed bug #51006 (bug in fwrite section of the manual)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 03:00:02 2026 UTC