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: 2020-11-18 11:29 UTC
Votes:9
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: cmb (profile)
Status: Closed Package: SPL related
PHP Version: 5.4.0 OS: Windows Server 2003
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
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

Pull Requests

Pull requests:

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
 [2020-11-18 11:29 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-11-18 11:30 UTC] cmb@php.net
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
 [2020-11-30 15:04 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f1d11c118dfdc911f2f33babb9b2cba8bf5acb67
Log: Fix #62004: SplFileObject: fgets after seek returns wrong line
 [2020-11-30 15:04 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 13:01:31 2024 UTC