|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-10-19 06:44 UTC] kalle@php.net
[2010-10-19 06:44 UTC] kalle@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: kalle
[2010-10-19 06:44 UTC] kalle@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 15:00:01 2026 UTC |
Description: ------------ The code example for fgets() trys to echo a "false" value the last time, and that is not too good, imo. The reader gets the impression that feof($handle) returns true before fgets($handle) returns false, which is not correct. Below you can see a different possible variant for a code example. Cheers. Test script: --------------- <?php /* -- original -- */ $handle = @fopen("/tmp/inputfile.txt", "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); echo $buffer; } fclose($handle); } /* -- a better one -- */ $handle = @fopen("/tmp/inputfile.txt", "r"); if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { echo $buffer; } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; } fclose($handle); } ?>