PHP Memory Lane - Commie

Note: Opinions expressed on this site do not reflect the views of clients, employers, or any organizations affiliated with past or present.

A Third Trip Down Memory Lane with commie

The memory lane tour continues. After carbon-nbd and carbon-fy, I pointed the same process at the oldest of the three: commie.

commie is a small object-oriented wrapper around PHP’s built-in CSV handling. The name is a play on “comma” as in “Comma Separated Value (CSV)” (and maybe some old 80’s action film fun). The idea was that nobody enjoyed reaching for fgetcsv and juggling column indexes by hand. With commie you read a row and grab columns by heading name, and you can jump around the file without loading the whole thing:

use Commie\CSVFile;

$csv = new CSVFile(new SplFileObject('./file.csv'), true);

while (($row = $csv->read())) {
    echo $row->col('My Heading')->value();
}

echo $csv->row(10)->col('TOTAL')->value();

There is a mapper concept layered on top so you can bend the parsing to whatever odd delimited format reality hands you, because it always does. The mapper is what turns header labels into column offsets, and you can swap in your own. Headers from some enterprise export often arrive padded and case-mangled, so normalize them on the way in:

use Commie\CSVColMapper;

class NormalizingMapper extends CSVColMapper {
    public function mapLabel(string $label, int $mapping): void {
        parent::mapLabel(strtolower(trim($label)), $mapping);
    }
}

$csv->setMapper(new NormalizingMapper($header, true));

echo $csv->row(10)->col('total')->value(); // ' TOTAL ', 'Total', ' total ', all the same to us now

The repo dates back to 2013, which means this library just quietly crossed 13 years. Thirteen. That still surprises me. The code, meanwhile, was exactly what you would expect from that era: PHP 5.x, old-style tests, no CI worth the name.

Same playbook as the last two posts. I handed my local LLM the modernized repos as the reference pattern, let it run the checklist, and reviewed every proposed change. Composer manifest, strict types, PHPUnit on a modern version, GitHub Actions for CI. A few prompts, a couple of review passes, and voila, PHP 8.1 ready!

Three for three now. There is something satisfying about old code waking up on a modern runtime without losing the shape I gave it a decade ago. Find commie on Packagist or GitHub.