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

From: Date: Wed, 18 Nov 2020 11:30:38 +0000
Subject: Bug #62004 [PATCH]: SplFileObject: fgets after seek returns wrong line
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230420@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
 Patch added by:     cmb@php.net
 Reported by:        don dot binda at verizon dot net
 Summary:            SplFileObject: fgets after seek returns wrong line
 Status:             Assigned
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows Server 2003
 PHP Version:        5.4.0
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

The following pull request has been associated:

Patch Name: Fix #62004: SplFileObject: fgets after seek returns wrong line
On GitHub:  https://github.com/php/php-src/pull/6434
Patch:      https://github.com/php/php-src/pull/6434.patch


Previous Comments:
------------------------------------------------------------------------
[2014-09-22 22:12:04] tim_siebels_aurich at yahoo dot de

This is not just 5.4.0
This exists since always and isn't fixed in any version
http://3v4l.org/KL7Z3

------------------------------------------------------------------------
[2013-01-23 21:43:56] sebak_pl1 at gazeta dot pl

Same for me. PHP v5.4.11

------------------------------------------------------------------------
[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 (#230420) next »