---
title: "League CSV: Buffer::nth() after row deletions in PHP"
description: "A fix to League CSV, a PHP library for CSV data: Buffer::nth() and nthAsObject() return the right record after earlier rows were deleted from the buffer."
url: "https://vulcode.com/en/opensource/contributions/league-csv"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

thephpleague/csv

# League CSV

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

[See the repository](https://github.com/thephpleague/csv) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: PHP
- **GitHub stars**: 3,478
- **Merged changes**: 1
- **Project site**: [csv.thephpleague.com](https://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](https://github.com/thephpleague/csv/pull/594)

## Merged change 1

- [#594 fix: make Buffer::nth() positional so it stays correct after deletions Merged 5 September 2026](https://github.com/thephpleague/csv/pull/594)

## 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](https://vulcode.com/en/technologies/php)

## Other projects we write code for

- [**Composer** PHP · 29,590 stars The dependency manager for PHP: it installs and updates a project's libraries from its composer.json.](https://vulcode.com/en/opensource/contributions/composer)

- [**PHPMailer** PHP · 22,347 stars The classic PHP library for sending email, used by WordPress and many other systems.](https://vulcode.com/en/opensource/contributions/phpmailer)

- [**Monolog** PHP · 21,407 stars A PHP logging library that sends records to files, sockets, inboxes, databases and web services. Symfony and Laravel use it, among others.](https://vulcode.com/en/opensource/contributions/monolog)

- [**Carbon** PHP · 16,583 stars A PHP DateTime extension for working with dates, standard in the Laravel ecosystem.](https://vulcode.com/en/opensource/contributions/carbon)

- [**Whoops** PHP · 13,231 stars A PHP library that turns uncaught exceptions into a readable error page with the stack trace, known from Laravel.](https://vulcode.com/en/opensource/contributions/whoops)

- [**ramsey/uuid** PHP · 12,642 stars A PHP library for generating universally unique identifiers (UUIDs).](https://vulcode.com/en/opensource/contributions/ramsey-uuid)

## Describe your project.

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

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
