Req #48421 [NoF->Opn]: stream_get_line() - allow $length to be optional

From: Date: Sat, 03 Jan 2015 13:27:58 +0000
Subject: Req #48421 [NoF->Opn]: stream_get_line() - allow $length to be optional
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189625@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48421&edit=1

 ID:                 48421
 Updated by:         nikic@php.net
 Reported by:        ryan dot brothers at gmail dot com
 Summary:            stream_get_line() - allow $length to be optional
-Status:             No Feedback
+Status:             Open
 Type:               Feature/Change Request
 Package:            Streams related
 Operating System:   Irrelevant
 PHP Version:        Any
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2015-01-03 13:05:45] ryan dot brothers at gmail dot com

Yes, I am still interested in this.  It wouldn't let me re-open the bug.

------------------------------------------------------------------------
[2014-12-30 10:41:33] php-bugs at lists dot php dot net

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.

------------------------------------------------------------------------
[2014-05-05 02:03:45] ryan dot brothers at gmail dot com

Yes, this would still be useful to me.  I've had to work around it in the meantime.  Thanks for
your help.

------------------------------------------------------------------------
[2014-04-30 22:48:57] levim@php.net

Is this something you are still interested in seeing?

------------------------------------------------------------------------
[2009-05-28 22:42:24] ryan dot brothers at gmail dot com

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 this bug report at https://bugs.php.net/bug.php?id=48421&edit=1


Thread (13 messages)

« previous php.bugs (#189625) next »