thephpleague/csv

getRecords with defined header produce wrong results

adalbertus opened this issue · 1 comments

Bug Report

Information Description
Version 9.11.0
PHP version PHP 8.1.23
OS Platform Ubuntu 22.04.2 LTS

Summary

I was trying to use getRecords with header set based on provided example in documentation. Problem is that it is not working
as I expected. It returns wrong result.

Standalone code, or other way to reproduce the problem

Here is sample code (copied exactly from documentation - https://csv.thephpleague.com/9.0/reader/tabular-data-reader/).

use League\Csv\Reader;

$csv = <<<CSV
Abel,14,M,2004
Abiga,6,F,2004
Aboubacar,8,M,2004
Aboubakar,6,M,2004
CSV;

$reader = Reader::createFromString($csv);
$resultSet = Statement::create()->process($reader);
$records = $resultSet->getRecords([3 => 'Year', 0 => 'Firstname', 4 => 'Yolo']);

Expected result

Based on documentation I expect that $records will contain items like:

[
     "Year" => "2004",
     "Firstname" => "Abel",
     "Yolo" => null,
 ]

Actual result

But actual result is:

[
     "Year" => "Abel",
     "Firstname" => "14",
     "Yolo" => "M",
 ]

Am I missing something?

@adalbertus the documentation is in sync with the master which means tried a feature no yet in production. As state in the documentation this feature will be available when version 9.12 is released. Hopefully next week depending on my free time and my last tests to validate the new behaviour.