note 121109 added to splfileobject.next
| From: | quijote dot shin at gmail dot com | Date: | Sun, 21 May 2017 21:03:03 +0000 |
| Subject: | note 121109 added to splfileobject.next | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209079@lists.php.net to get a copy of this message | ||
As @Jonnycake pointed there is no documentation about the following behavior of next();
You need to call current() to really move forward without the need of a source loop.
Be:
<?php
$file = new SplFileObject("file.txt");
echo PHP_EOL . $file->current();
$file->next();
$file->next();
$file->next();
echo PHP_EOL . $file->current(); // 2nd line of the file
?>
<?php
$file = new SplFileObject("file.txt");
echo PHP_EOL . $file->current();
$file->next(); $file->current();
$file->next(); $file->current();
$file->next();
echo PHP_EOL . $file->current(); // be the 4th line of the file
?>
Honestly, I don't know if it is waste of memory and/or CPU .
----
Server IP: 200.29.231.32
Probable Submitter: 158.251.255.240
----
Manual Page -- http://php.net/manual/en/splfileobject.next.php
Edit -- https://master.php.net/note/edit/121109
Del: integrated -- https://master.php.net/note/delete/121109/integrated
Del: useless -- https://master.php.net/note/delete/121109/useless
Del: bad code -- https://master.php.net/note/delete/121109/bad+code
Del: spam -- https://master.php.net/note/delete/121109/spam
Del: non-english -- https://master.php.net/note/delete/121109/non-english
Del: in docs -- https://master.php.net/note/delete/121109/in+docs
Del: other reasons-- https://master.php.net/note/delete/121109
Reject -- https://master.php.net/note/reject/121109
Search -- https://master.php.net/manage/user-notes.php