|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-12-11 21:07 UTC] cataphract@php.net
[2011-12-11 21:08 UTC] cataphract@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: cataphract
[2011-12-11 21:08 UTC] cataphract@php.net
[2012-01-22 20:30 UTC] cataphract@php.net
[2012-03-05 01:55 UTC] stas@php.net
-Status: Closed
+Status: Re-Opened
[2012-03-05 01:55 UTC] stas@php.net
[2012-04-18 09:46 UTC] laruence@php.net
[2012-04-18 09:46 UTC] laruence@php.net
[2012-07-24 23:37 UTC] rasmus@php.net
[2012-07-24 23:38 UTC] rasmus@php.net
[2012-09-01 16:14 UTC] cataphract@php.net
-Status: Re-Opened
+Status: Open
[2012-09-01 16:15 UTC] cataphract@php.net
-Status: Assigned
+Status: Closed
[2013-11-17 09:34 UTC] laruence@php.net
[2013-11-17 09:34 UTC] laruence@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 04:00:02 2025 UTC |
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) ""