Bug #65492 [NEW]: Seeking beyond EOF leads to inconsistent results for key() and current()
| From: | foo at example dot com | Date: | Wed, 21 Aug 2013 06:50:48 +0000 |
| Subject: | Bug #65492 [NEW]: Seeking beyond EOF leads to inconsistent results for key() and current() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-181079@lists.php.net to get a copy of this message | ||
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