|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43522 stream_get_line eats additional characters
Submitted: 2007-12-06 17:16 UTC Modified: 2007-12-10 14:40 UTC
From: tylera at iproduction dot com Assigned:
Status: Closed Package: Streams related
PHP Version: 5.2.5 OS: Gentoo Linux, Win32, Solaris
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
16 - 5 = ?
Subscribe to this entry?

 [2007-12-06 17:16 UTC] tylera at iproduction dot com
Calling stream_get_line may eat additional characters when reading a long line.  If the delimiter is not encountered, a number of additional characters are removed from the stream and are not returned with the next call to stream_get_line.  For some unknown reason, adding \r to the delimiter makes it work just fine.

Reproduce code:

$fp = fopen('test.php', 'r'); // Open myself
DoTest($fp, 'ZZZ');  // Removes 3 characters
DoTest($fp, "\r");  // Doesn't break with \r for some reason

function DoTest($fp, $delim) {
	echo "Delim:  " . urlencode($delim) . "\n";
	echo "   " . stream_get_line($fp, 10, $delim) . "\n";
	echo "   " . stream_get_line($fp, 10, $delim) . "\n";

Expected result:
Delim:  ZZZ
   <?PHP // 1
Delim:  %0D
   <?PHP // 1

Actual result:
Delim:  ZZZ
   <?PHP // 1
Delim:  %0D
   <?PHP // 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-08 20:25 UTC]
Simple patch for it:
 [2007-12-10 14:19 UTC]
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at

 [2007-12-10 14:40 UTC] tylera at iproduction dot com
Even though you used the wrong canned response, I appreciate that you fixed the bug.  Can't wait for 5.2.6 or 5.3.0 to be released.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jun 05 00:01:30 2020 UTC