Bug #61032 [Ana]: False value for blank last line with SKIP_EMPTY andDROP_NEW_LINE
| From: | rasmus@php.net | Date: | Thu, 09 Feb 2012 22:25:59 +0000 |
| Subject: | Bug #61032 [Ana]: False value for blank last line with SKIP_EMPTY andDROP_NEW_LINE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167366@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61032&edit=1
ID: 61032
Updated by: rasmus@php.net
Reported by: jcampbell at remindermedia dot com
Summary: False value for blank last line with SKIP_EMPTY
andDROP_NEW_LINE
Status: Analyzed
Type: Bug
Package: SPL related
Operating System: Fedora 16
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
Until we fix this and to be compatible with the broken versions, you can simply
add SplFileObject::READ_AHEAD. This won't break anything for past nor future
versions since that is what SplFileObject::SKIP_EMPTY implied before.
Previous Comments:
------------------------------------------------------------------------
[2012-02-09 20:22:05] rasmus@php.net
This was caused by fixing bug 55807
------------------------------------------------------------------------
[2012-02-09 19:41:32] jcampbell at remindermedia dot com
Description:
------------
Suddenly, using SplFileObject::SKIP_EMPTY and SplFileObject::DROP_NEW_LINE no longer ignores a final
blank line in a file. Instead, when iterating over the file object, the last value is boolean false.
This appears to have changed between 5.3.8 and 5.3.9 and persists in 5.3.10.
Test script:
---------------
<?php
$filename = "/tmp/test-file.txt";
file_put_contents($filename, "non-blank line1" . PHP_EOL);
file_put_contents($filename, "non-blank line2" . PHP_EOL, FILE_APPEND);
$TheFile = new SplFileObject($filename, "r");
$TheFile->setFlags( SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE );
foreach ($TheFile as $line) {
print "Currently on key " . $TheFile->key() . ": " . PHP_EOL;
var_dump($line);
}
Expected result:
----------------
Currently on key 0:
string(15) "non-blank line1"
Currently on key 1:
string(15) "non-blank line2"
Actual result:
--------------
Currently on key 0:
string(15) "non-blank line1"
Currently on key 1:
string(15) "non-blank line2"
Currently on key 2:
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61032&edit=1