From:             michael dot virnstein at brodos dot de
Operating system: 
PHP version:      4.4.4
PHP Bug Type:     Streams related
Bug description:  fgets doesn't work as expected

Description:
------------
i recognized a change to fgets function, which i think is a bug. 
When i try to fetch data from a file handle via fgets, which has been
opened via fopen for a local file or url, the lenght parameter now has to
be supplied as length+1 to get the desired result.
E.g. fgets($fp, 1) returns false now, fgets($fp, 2) returns the first
letter, fgets($fp, 3) returns the first two letters ...
This bug is present in 4.4.4 and 5.1.x, couldn't test 5.2 yet.

Reproduce code:
---------------
<?php

$fp = fopen('http://www.php.net', 'r')
  or die ('could not connect');

var_dump(fgets($fp, 1)); // returns false

var_dump(fgets($fp, 2)); // returns first letter

fclose($fp);


?>

Expected result:
----------------
- first var_dump should return first letter
- second var_dump should return next two letter

Actual result:
--------------
- first var_dump returns false
- second var_dump returns first letter

-- 
Edit bug report at http://bugs.php.net/?id=39433&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39433&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39433&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39433&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39433&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39433&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39433&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39433&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39433&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39433&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39433&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39433&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39433&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39433&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39433&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39433&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39433&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39433&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39433&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39433&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39433&r=mysqlcfg

Reply via email to