#48420 [Opn->Fbk]: stream_get_line() - invalid result when passing $length and $ending
| From: | lbarnaud@php.net | Date: | Fri, 29 May 2009 08:39:03 +0000 |
| Subject: | #48420 [Opn->Fbk]: stream_get_line() - invalid result when passing $length and $ending | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137863@lists.php.net to get a copy of this message | ||
ID: 48420
Updated by: lbarnaud@php.net
Reported By: ryan dot brothers at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: Streams related
Operating System: Linux
PHP Version: 5.2.9
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
Previous Comments:
------------------------------------------------------------------------
[2009-05-28 22:21:09] ryan dot brothers at gmail dot com
Description:
------------
When you pass to stream_get_line() a $length that is greater than the
file size and a $ending that does not appear in the file,
stream_get_line() returns bool(false) rather than the string that is in
your file.
In the below example, when I run stream_get_line() passing in a $length
of 6 and a $ending of "\n", stream_get_line() returns false rather than
the contents of the file.
The manual states "Reading ends when length bytes have been read, when
the string specified by ending is found (which is not included in the
return value), or on EOF (whichever comes first).", so I believe the
contents of my file should be returned since EOF is first to be reached.
Reproduce code:
---------------
<?php
$fp = tmpfile();
fwrite($fp, '12345');
fseek($fp, 0);
var_dump(stream_get_line($fp, 5));
fseek($fp, 0);
var_dump(stream_get_line($fp, 6));
fseek($fp, 0);
var_dump(stream_get_line($fp, 5, "\n"));
fseek($fp, 0);
var_dump(stream_get_line($fp, 6, "\n"));
fclose($fp);
Expected result:
----------------
string(5) "12345"
string(5) "12345"
string(5) "12345"
string(5) "12345"
Actual result:
--------------
string(5) "12345"
string(5) "12345"
string(5) "12345"
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48420&edit=1