facebook / facebook/hhvm

SplFileObject::fgetcsv does not return null for last line in CSV mode

Open
#5,823 2 comments 0 reactions 0 assignees View on GitHub
php5 incompatibility
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

I'm reading CSV files using SplFileObject class and `fgetcsv` method. Below code does not work as intended in HHVM 3.8.0 meaning `fgetcsv` does return `false` on the LAST line. In PHP 5.6.7-1 the last line returns `null`.

With the following CSV file

``` csv
row11;;row13
row21;row22;row23

```

and the following code

``` php
$aFile = new SplFileObject ($aPath);
$aFile->setFlags(SplFileObject::SKIP_EMPTY | SplFileObject::READ_AHEAD | SplFileObject::DROP_NEW_LINE | SplFileObject::READ_CSV);
$aFile->setCsvControl(';');

for($i = 0; $i < 3; $i++) {
$row = $aFile->fgetcsv();
var_dump($row);
}
```

Result for PHP

```
array(3) {
[0] =>
string(5) "row11"
[1] =>
string(0) ""
[2] =>
string(5) "row13"
}
array(3) {
[0] =>
string(5) "row21"
[1] =>
string(5) "row22"
[2] =>
string(5) "row23"
}
NULL
```

Result for HHVM

```
array(3) {
[0]=>
string(5) "row11"
[1]=>
string(0) ""
[2]=>
string(5) "row13"
}
array(3) {
[0]=>
string(5) "row21"
[1]=>
string(5) "row22"
[2]=>
string(5) "row23"
}
bool(false)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.