-
-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Since 9.12.0 TabularDataReader::getRecords is stricter - exception is thrown with string keys for header #518
Comments
@pwolanin thanks for using the package. The change is described on the CHANGELOG in the 9.12.0 release notes. The described issue is discussed there too. Also |
In my copy of the code at 9.14.0 it has this:
As the doc for:
Which is the method that throws the exception. So I think there is a problem or unexpected change here. |
@pwolanin as stated the change is expected and described in various locations of the package. |
@pwolanin what I may do is maybe update the change and do an Would that be acceptable as a mitigation path for you ? Keep in mind that this mitigation would only work in v9 and will be removed in v10. Whenever that version comes out. |
@nyamsprod I think that would be helpful to avoid a perceived API change. In my case I can fix the exception by calling array_values() in my code on the header array, but other people may not have as much control. |
@pwolanin question can you share a snippet on how you submitted a records with an header with string keys ? Reason I am asking is because the mitigation is breaking more things than expected so I am not confident in implemeting it. |
So this is in the context of a Drupal CSV migration. My code is a subclass of CSV.php and overrides the public function initializeIterator() to add some extra logic. Looking now I see there is an array_values() call in CSV.php. My code does this after constructing the header, and where I just added the array_values() call to fix the exception:
If I condense that logic down, it's basically:
Perhaps the difference is that the header array is being passed in to getRecords() and you're expecting an empty array coming in for your more common use? |
yes either an empty array or a array with integer as array-key. I find it strange or uncommon to give header an array with array-key as string. So adding some mitigation adds some side-effects inside the internal codebase that I do not want to tackle. So I am a bit torn in a sense that I believe the error message is a better way of handling the situation as it
While the proposed work around adds another type of implicit rule about conversion the user may not be aware of. Also with the current code, the following is already acceptable $reader = Reader::createFromString($csv);
dump([...$reader->getRecords(['1' => 'toto', 4 => 'tata', '3' => 'tutu'])]); As PHP will implicitly convert the string On the other hand, to me, the following should have failed a long time ago. At least if it use to work, to me, it was a bug: $reader = Reader::createFromString($csv);
dump([...$reader->getRecords(['toto' => 'toto', 'tata' => 'tata', 'tutu' => 'tutu'])]); |
Sure, I don't think it's essential to add the mitigation since the fix should usually be easy. Maybe fix the doc on |
doc block improve for internal |
(Fill in the relevant information below to help triage your issue.)
Question
There is a change from #499
7ccbe6d
This causes the Reader to throw an exception when the header keys are not numeric.
This behavior change is not documented or expected based on the release notes - is this a bug?
It worked fine before this release to have string keys for the header and the code could just call
array_values()
instead of throwing an exception.https://github.com/thephpleague/csv/releases/tag/9.14.0
Checks before submitting
The text was updated successfully, but these errors were encountered: