Edit report at https://bugs.php.net/bug.php?id=60455&edit=1
ID: 60455 Updated by: s...@php.net Reported by: jakub dot lopuszanski at nasza-klasa dot pl Summary: stream_get_line reports two lines instead of one -Status: Closed +Status: Re-Opened Type: Bug Package: Streams related Operating System: linux PHP Version: Irrelevant Assigned To: cataphract Block user comment: N Private report: N New Comment: Reopened to track 5.4. Please merge into 5.4 and close. Previous Comments: ------------------------------------------------------------------------ [2012-01-22 20:30:37] cataphr...@php.net Automatic comment from SVN on behalf of cataphract Revision: http://svn.php.net/viewvc/?view=revision&revision=322582 Log: - Further fix for bug #60455 (stream_get_line misbehaves if EOF is not detected together with the last read). - Fixed bug #60817 (stream_get_line() reads from stream even when there is already sufficient data buffered). stream_get_line() now behaves more like fgets(), as is documented. #withheld commit to 5.4 ------------------------------------------------------------------------ [2011-12-11 21:08:51] cataphr...@php.net Fixed in SVN. Thanks. ------------------------------------------------------------------------ [2011-12-11 21:07:57] cataphr...@php.net Automatic comment from SVN on behalf of cataphract Revision: http://svn.php.net/viewvc/?view=revision&revision=320876 Log: - Fixed bug #60455: stream_get_line misbehaves if EOF is not detected together with the last read. ------------------------------------------------------------------------ [2011-12-07 10:01:42] jakub dot lopuszanski at nasza-klasa dot pl Description: ------------ If a file consists of single line, and you use a straightforward loop over all lines using stream_get_line, you may be suprised that there are actually two lines, where the second one is empty string. This is inconsistent with the case where you actually have two lines in a file, and stream_get_line reports two lines as expected without the additional empty third line. This inconsistency makes it quite difficult to write a correct code. Test script: --------------- I have three files: lopuszanski@vanisoft:~$ hexdump -C one_line.txt 00000000 61 0a |a.| 00000002 lopuszanski@vanisoft:~$ hexdump -C two_lines.txt 00000000 61 0a 62 0a |a.b.| 00000004 lopuszanski@vanisoft:~$ hexdump -C two_lines_one_of_which_is_empty.txt 00000000 61 0a 0a |a..| 00000003 And the following script: lopuszanski@vanisoft:~$ cat test.php <?php while(!feof(STDIN)){ $line = stream_get_line(STDIN,1000000,"\n"); var_dump($line); } ?> Expected result: ---------------- lopuszanski@vanisoft:~$ php test.php < one_line.txt string(1) "a" lopuszanski@vanisoft:~$ php test.php < two_lines.txt string(1) "a" string(1) "b" lopuszanski@vanisoft:~$ php test.php < two_lines_one_of_which_is_empty.txt string(1) "a" string(0) "" Actual result: -------------- lopuszanski@vanisoft:~$ php test.php < one_line.txt string(1) "a" string(0) "" lopuszanski@vanisoft:~$ php test.php < two_lines.txt string(1) "a" string(1) "b" lopuszanski@vanisoft:~$ php test.php < two_lines_one_of_which_is_empty.txt string(1) "a" string(0) "" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60455&edit=1