All contributions

thephpleague/csv

League CSV

A PHP library from The PHP League for reading, writing and processing CSV data, including an in-memory buffer.

Language
PHP
GitHub stars
3,478
Merged changes
1
Project site
csv.thephpleague.com

What we changed

Buffer::nth() and nthAsObject() are positional, so they return the right record even after earlier rows were deleted.

What this work shows

  • Positional indexes versus array keys in PHP
  • A consistent API contract across classes
  • PHPUnit edge-case tests
What was broken

nth() returned the wrong record after a delete

Buffer::delete() removes rows without renumbering the keys, while nth() looked the record up as the first key plus n. After deleting the second of five records, nth(1) returned an empty array and nth(4) returned a record that was no longer at that position.

How we fixed it

A positional index, as in ResultSet::nth()

nth() and nthAsObject() now find the record by its position in iteration order, so they agree with getRecords() and ResultSet::nth(). A test deletes a middle record and checks every position and the empty result past the end.

#594

Merged change 1

  1. #594 fix: make Buffer::nth() positional so it stays correct after deletions Merged 5 September 2026

What it taught us

An index that was a key stops being a position after the first deletion. An API must say which of the two it is and behave like similar methods in the library's other classes.

More about this technology: PHP

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.