php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62004 SplFileObject: fgets after seek returns wrong line
Submitted: 2012-05-11 13:59 UTC Modified: 2012-05-17 14:35 UTC
Votes:8
Avg. Score:4.2 ± 1.0
Reproduced:8 of 8 (100.0%)
Same Version:2 (25.0%)
Same OS:1 (12.5%)
From: don dot binda at verizon dot net Assigned:
Status: Open Package: SPL related
PHP Version: 5.4.0 OS: Windows Server 2003
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: don dot binda at verizon dot net
New email:
PHP Version: OS:

 

 [2012-05-11 13:59 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-17 14:35 UTC] don dot binda at verizon dot net
-PHP Version: Irrelevant +PHP Version: 5.4.0
 [2012-05-17 14:35 UTC] don dot binda at verizon dot net
Fixing version
 [2012-06-03 20:47 UTC] 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?
 [2013-01-23 21:43 UTC] sebak_pl1 at gazeta dot pl
Same for me. PHP v5.4.11
 [2014-09-22 22:12 UTC] 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
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 13:01:23 2019 UTC