Skip to content

Commit

Permalink
Merge pull request #116 from esmero/ISSUE-115
Browse files Browse the repository at this point in the history
ISSUE-115:Replace ::seek() with multiple ::next() to work around bug in PHP8/7/6/5
  • Loading branch information
DiegoPino authored Aug 5, 2022
2 parents 4eee4c7 + 492a3de commit 119d322
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/AmiUtilityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,12 @@ public function csv_read(File $file, int $offset = 0, int $count = 0, bool $alwa

if ($offset > 0 && !$always_include_header) {
// If header needs to be included then we offset later on
$spl->seek($offset);
// PHP 8.0.16 IS STILL BUGGY with SEEK.
//$spl->seek($offset) does not work here.
for ($i = 0; $i < $offset; $i++) {
$spl->next();
}

}
$data = [];
$seek_to_offset = ($offset > 0 && $always_include_header);
Expand All @@ -1083,7 +1088,11 @@ public function csv_read(File $file, int $offset = 0, int $count = 0, bool $alwa
$data[] = $spl->fgetcsv();
}
if ($seek_to_offset) {
$spl->seek($offset);
for ($i = 0; $i < $offset; $i++) {
$spl->next();
}
// PHP 8.0.16 IS STILL BUGGY with SEEK.
//$spl->seek($offset); doe snot work here
// So we do not process this again.
$seek_to_offset = FALSE;
}
Expand Down

0 comments on commit 119d322

Please sign in to comment.