#48421 [NEW]: stream_get_line() - allow $length to be optional
From: ryan dot brothers at gmail dot com
Operating system: Linux
PHP version: 5.2.9
PHP Bug Type: Feature/Change Request
Bug description: stream_get_line() - allow $length to be optional
Description:
------------
I believe stream_get_line() should allow the $length parameter to be
optional by allowing a $length of -1 that would read the remaining buffer
up to either the $ending delimiter or EOF.
Currently if you pass a $length of 0, the $length defaults to
PHP_SOCK_CHUNK_SIZE (8192) in ext/standard/streamsfuncs.c. If you pass a
length of -1, a PHP Warning is generated.
Other 'similar' functions that allow length to be optional or -1 are
fgets, stream_get_contents, and file_get_contents.
Also, the manual page for stream_get_line() states that this function is
the same fgets() except for the handling of the delimiter - but another
difference, at least right now, is that the $length parameter is required
in stream_get_line(), but optional in fgets().
Reproduce code:
---------------
<?php
$fp = tmpfile();
fwrite($fp, str_repeat('a', 10000));
fseek($fp, 0);
echo strlen(stream_get_line($fp, 0));
fseek($fp, 0);
echo strlen(stream_get_line($fp, -1));
fclose($fp);
Expected result:
----------------
8192
10000
Actual result:
--------------
8192
Warning: stream_get_line(): The maximum allowed length must be greater
than or equal to zero
--
Edit bug report at http://bugs.php.net/?id=48421&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48421&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48421&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48421&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48421&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48421&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48421&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48421&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48421&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48421&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48421&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48421&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48421&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48421&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48421&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48421&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48421&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48421&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48421&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48421&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48421&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48421&r=mysqlcfg
Thread (13 messages)
- ryan dot brothers at gmail dot com
- levim@php.netReq #48421 [Opn->Fbk]: stream_get_line() - allow $length to be optional
- ryan dot brothers at gmail dot comReq #48421 [Com]: stream_get_line() - allow $length to be optional
- php-bugs at lists dot php dot netReq #48421 [Fbk->NoF]: stream_get_line() - allow $length to be optional
- ryan dot brothers at gmail dot comReq #48421 [Com]: stream_get_line() - allow $length to be optional
- nikic@php.netReq #48421 [NoF->Opn]: stream_get_line() - allow $length to be optional
- n at n0099 dot netReq #48421 [Com]: stream_get_line() - allow $length to be optional
- cmb@php.netReq #48421 [Opn->Fbk]: stream_get_line() - allow $length to be optional
- ryan dot brothers at gmail dot comReq #48421 [Com]: stream_get_line() - allow $length to be optional
- cmb@php.netReq #48421 [Fbk->Opn]: stream_get_line() - allow $length to be optional
- crezasgov@aol.comReq #48421 [PATCH]: stream_get_line() - allow $length to be optional
- crezasgov@aol.comReq #48421 [PATCH]: stream_get_line() - allow $length to be optional
- maghsodid@yahoo.comReq #48421 [PATCH]: stream_get_line() - allow $length to be optional