Bug #66001 [NEW]: Problem with SplFileObject::seek()

From: Date: Wed, 30 Oct 2013 12:10:11 +0000
Subject: Bug #66001 [NEW]: Problem with SplFileObject::seek()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182494@lists.php.net to get a copy of this message
From:             miichal dot kozlowski at gmail dot com
Operating system: Win & Unix
PHP version:      Irrelevant
Package:          SPL related
Bug Type:         Bug
Bug description:Problem with SplFileObject::seek()

Description:
------------
Hi,
Example 1 shows we set $file->seek(0) and it will return 3 rows:

Array
(
    [0] => 0DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => test
    [4] => FL
    [5] => 34221
)
Array
(
    [0] => 1DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)
Array
(
    [0] => 2DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)

Example 2 shows if we set $file->seek(1) then we are expecting to get 2
rows:

Array
(
    [0] => 1DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)
Array
(
    [0] => 2DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)

 ,but we received 1.

Array
(
    [0] => 2DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)



Test script:
---------------
<?php
file_put_contents('file.csv', '"0DATA";"1 St 1
Av";"";"test";"FL";"34221"' . PHP_EOL .'
"1DATA";"1 St 1
Av";"";"Test";"FL";"34221"' . PHP_EOL .'
"2DATA";"1 St 1
Av";"";"Test";"FL";"34221"');
//example 1
$file = new SplFileObject('file.csv');
$file->seek(0);
while(!$file->eof()) {
    print_r($file->fgetcsv(";"));
}
echo '---' . PHP_EOL;
//example 2
$file = new SplFileObject('file.csv');
$file->seek(1);
while(!$file->eof()) {
    print_r($file->fgetcsv(";"));
}

Expected result:
----------------
Array
(
    [0] => 0DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => test
    [4] => FL
    [5] => 34221
)
Array
(
    [0] => 1DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)
Array
(
    [0] => 2DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)
example 2
Array
(
    [0] => 1DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)
Array
(
    [0] => 2DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)

Actual result:
--------------
Array
(
    [0] => 0DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => test
    [4] => FL
    [5] => 34221
)
Array
(
    [0] => 1DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)
Array
(
    [0] => 2DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)
example 2
Array
(
    [0] => 2DATA
    [1] => 1 St 1 Av
    [2] => 
    [3] => Test
    [4] => FL
    [5] => 34221
)

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



Thread (6 messages)

« previous php.bugs (#182494) next »