|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-09-01 10:09 UTC] kentaro at ranvis dot com
Description:
------------
SplFileObject->next() doesn't move to the next line unless ->current() is called in advance.
Test script:
---------------
$f = new SplFileObject('php://memory', 'r+');
$f->fwrite("line 1\nline 2\nline 3");
$f->rewind();
assert('$f->current() === "line 1\n"');
$f->next();
assert('$f->current() === "line 2\n"');
$f->next();
var_dump($f->ftell()); // 14
assert('$f->current() === "line 3"');
$f->rewind();
$f->next();
$f->next();
var_dump($f->ftell()); // 0
assert('$f->current() === "line 3"'); // fails
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 16:00:01 2025 UTC |
Consider: <?php $f = new SplFileObject('php://temp', 'w+'); $f->fwrite("line 1\nline 2\nline 3"); $f->rewind(); $f->next(); $f->next(); $f->next(); var_dump($f->key()); var_dump($f->current()); While key() says we're at line 3, current() returns the first line. That doesn't make sense; either key() should return 1, or current() should return the third line.