|  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
Avg. Score:4.3 ± 0.9
Reproduced:9 of 9 (100.0%)
Same Version:2 (22.2%)
Same OS:1 (11.1%)
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-05-11 13:59 UTC] don dot binda at verizon dot net
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

$f = new SplFileObject('temp.txt');
echo $f->fgets();
echo $f->fgets();
echo $f->fgets();

Expected result:
Line 1
Line 2
Line 3

Actual result:
Line 1
Line 3
Line 4


Add a Patch

Pull Requests

Add a Pull Request


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
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 20 07:01:23 2020 UTC