[PHP-BUG] Bug #65492 [NEW]: Seeking beyond EOF leads to inconsistent results for key() and current()

2013-08-20 Thread foo at example dot com
From: foo at example dot com
Operating system: any
PHP version:  Irrelevant
Package:  SPL related
Bug Type: Bug
Bug description:Seeking beyond EOF leads to inconsistent results for key() and 
current()

Description:

When seek()'ing beyond the end of file in an SplFileObject,
SplFileObject::key() 
will return the number of the last line in the file but
SplFileObject::current() 
will return false. This is inconsistent. 

Either SplFileObject::current() returns the content of the last line then,
too. Or 
SplFileObject::key() should return false as well. As an alternative, 
SplFileObject::seek() could raise an OutOfBoundsException when trying to
seek 
beyond EOF.

Test script:
---
$txt = <<< TXT
foo
bar
baz
TXT;

$file = new SplTempFileObject(-1);
$file->fwrite($txt);
$file->seek(100);
var_dump( $file->key(), $file->fgetcsv());

Expected result:

int(2)
baz

or

false
false

or 

OutOfBoundsException

Actual result:
--
int(2)
NULL

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



Bug #65492 [Opn]: Seeking beyond EOF leads to inconsistent results for key() and current()

2013-08-20 Thread foo at example dot com
Edit report at https://bugs.php.net/bug.php?id=65492&edit=1

 ID: 65492
 User updated by:    foo at example dot com
 Reported by:    foo at example dot com
 Summary:Seeking beyond EOF leads to inconsistent results for
 key() and current()
 Status: Open
 Type:   Bug
 Package:SPL related
 Operating System:   any
 PHP Version:Irrelevant
 Block user comment: N
 Private report: N

 New Comment:

Sorry, the last line in the Test Script should read

var_dump( $file->key(), $file->current() );

The problem does exist for fgetcsv() though, too. It will return NULL instead 
of 
the data at the last line.


Previous Comments:

[2013-08-21 06:50:48] foo at example dot com

Description:

When seek()'ing beyond the end of file in an SplFileObject, 
SplFileObject::key() 
will return the number of the last line in the file but 
SplFileObject::current() 
will return false. This is inconsistent. 

Either SplFileObject::current() returns the content of the last line then, too. 
Or 
SplFileObject::key() should return false as well. As an alternative, 
SplFileObject::seek() could raise an OutOfBoundsException when trying to seek 
beyond EOF.

Test script:
---
$txt = <<< TXT
foo
bar
baz
TXT;

$file = new SplTempFileObject(-1);
$file->fwrite($txt);
$file->seek(100);
var_dump( $file->key(), $file->fgetcsv());

Expected result:

int(2)
baz

or

false
false

or 

OutOfBoundsException

Actual result:
--
int(2)
NULL






-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65492&edit=1