php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61032 False value for blank last line with SKIP_EMPTY andDROP_NEW_LINE
Submitted: 2012-02-09 19:41 UTC Modified: 2020-11-03 17:56 UTC
Votes:5
Avg. Score:2.6 ± 0.8
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jcampbell at remindermedia dot com Assigned: cmb (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.3.10 OS: Fedora 16
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jcampbell at remindermedia dot com
New email:
PHP Version: OS:

 

 [2012-02-09 19:41 UTC] 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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-09 20:22 UTC] rasmus@php.net
This was caused by fixing bug 55807
 [2012-02-09 20:22 UTC] rasmus@php.net
-Status: Open +Status: Analyzed
 [2012-02-09 22:25 UTC] rasmus@php.net
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.
 [2012-02-09 22:46 UTC] jcampbell at remindermedia dot com
Thanks. I should have realized that after reading bug 55807.
 [2016-06-29 12:40 UTC] cmb@php.net
According to the changelog[1] and the sources the "broken fix" is
available as of PHP 5.3.9. (<https://3v4l.org/Ad364> reports
otherwise, though.) That is already documented in the Changelog
section of the SplFileObject man page[2]. It appears to me that
this report should be marked as WONTFIX.

[1] <http://php.net/ChangeLog-5.php>
[2] <http://php.net/manual/en/class.splfileobject.php>
 [2020-11-03 17:56 UTC] cmb@php.net
-Status: Analyzed +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-11-03 17:56 UTC] cmb@php.net
Well, actually not a bug at all.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC