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

From: Date: Fri, 11 May 2012 13:59:04 +0000
Subject: Bug #62004 [NEW]: SplFileObject: fgets after seek returns wrong line
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-170377@lists.php.net to get a copy of this message
From:             
Operating system: Windows Server 2003
PHP version:      Irrelevant
Package:          SPL related
Bug Type:         Bug
Bug description:SplFileObject: fgets after seek returns wrong line

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 bug report at https://bugs.php.net/bug.php?id=62004&edit=1
-- 
Try a snapshot (PHP 5.4):            https://bugs.php.net/fix.php?id=62004&r=trysnapshot54
Try a snapshot (PHP 5.3):            https://bugs.php.net/fix.php?id=62004&r=trysnapshot53
Try a snapshot (trunk):              https://bugs.php.net/fix.php?id=62004&r=trysnapshottrunk
Fixed in SVN:                        https://bugs.php.net/fix.php?id=62004&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62004&r=needdocs
Fixed in release:                    https://bugs.php.net/fix.php?id=62004&r=alreadyfixed
Need backtrace:                      https://bugs.php.net/fix.php?id=62004&r=needtrace
Need Reproduce Script:               https://bugs.php.net/fix.php?id=62004&r=needscript
Try newer version:                   https://bugs.php.net/fix.php?id=62004&r=oldversion
Not developer issue:                 https://bugs.php.net/fix.php?id=62004&r=support
Expected behavior:                   https://bugs.php.net/fix.php?id=62004&r=notwrong
Not enough info:                     https://bugs.php.net/fix.php?id=62004&r=notenoughinfo
Submitted twice:                     https://bugs.php.net/fix.php?id=62004&r=submittedtwice
register_globals:                    https://bugs.php.net/fix.php?id=62004&r=globals
PHP 4 support discontinued:          https://bugs.php.net/fix.php?id=62004&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62004&r=dst
IIS Stability:                       https://bugs.php.net/fix.php?id=62004&r=isapi
Install GNU Sed:                     https://bugs.php.net/fix.php?id=62004&r=gnused
Floating point limitations:          https://bugs.php.net/fix.php?id=62004&r=float
No Zend Extensions:                  https://bugs.php.net/fix.php?id=62004&r=nozend
MySQL Configuration Error:           https://bugs.php.net/fix.php?id=62004&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#170377) next »