Bug #62004 [Com]: SplFileObject: fgets after seek returns wrong line

From: Date: Wed, 23 Jan 2013 21:43:56 +0000
Subject: Bug #62004 [Com]: SplFileObject: fgets after seek returns wrong line
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-176205@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62004&edit=1

 ID:                 62004
 Comment by:         sebak_pl1 at gazeta dot pl
 Reported by:        don dot binda at verizon dot net
 Summary:            SplFileObject: fgets after seek returns wrong line
 Status:             Open
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows Server 2003
 PHP Version:        5.4.0
 Block user comment: N
 Private report:     N

 New Comment:

Same for me. PHP v5.4.11


Previous Comments:
------------------------------------------------------------------------
[2012-06-03 20:47:26] carloschilazo at gmail dot com

Based on documentation, it says that fgets Returns:

Returns a string containing the NEXT line from the file

wouldn't that explain?

------------------------------------------------------------------------
[2012-05-17 14:35:16] don dot binda at verizon dot net

Fixing version

------------------------------------------------------------------------
[2012-05-11 13:59:04] don dot binda at verizon dot net

Description:
------------
This is occurring in 5.4.0, although 5.4.x isn't an option under version.

Appears to be related to (or same as) 46569:

Calling fgets() after seek() to any non-zero line returns one line later than expected. seek(0)
works fine and calling current() instead of fgets() also works correctly.

Test script:
---------------
Source file (temp.txt):
Line 1
Line 2
Line 3
Line 4

Code:
$f = new SplFileObject('temp.txt');
$f->seek(0);
echo $f->fgets();
$f->seek(1);
echo $f->fgets();
$f->seek(2);
echo $f->fgets();

Expected result:
----------------
Line 1
Line 2
Line 3

Actual result:
--------------
Line 1
Line 3
Line 4


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62004&edit=1


Thread (7 messages)

« previous php.bugs (#176205) next »