-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
Docs: Fix sample code in documentation to use getRecords()
instead of getHeader()
#525
Conversation
@meihei3 The code you are trying to update is related to the header and is correct AFAIK. |
@nyamsprod Thank you for your feedback. I understand that While As a result, the current sample code does not produce the expected Thanks. |
@meihei3 the documentation is right but the implementation has a bug!! So I will convert your ticket into a bug issue that I will fix ASAP!! So the code needs to be changed not the documentation |
Now that I am thinking a bit about it you may be right. When you choose a row to be the header, if that row exists it should be returned as is. You did select the row afterall. What is triggering the error is when you try to use that row as a header. So should the exception be thrown when you still have not decided to use the header or when you are in fact using the error. If it's the former then it is a bug in the code ... if its the latter then it is a bug in the documentation 🤷🏾 |
I think that getHeader() does not need to call SyntaxError::dueToDuplicateHeaderColumnNames(). According to RFC 4180, duplicate header fields are not explicitly prohibited. However, getRecords() converts CSV rows into key-value PHP arrays. In this context, it is logical for SyntaxError::dueToDuplicateHeaderColumnNames() to be triggered during the conversion from CSV to PHP objects. |
Then let's merge your PR and be done with it 👍🏾 |
@nyamsprod Thank you! However, I don't have the permissions to merge this PR, so could you please merge it on my behalf? |
merged and thanks for the fix in documentation ... and for using the library. |
The validation for duplicated headers requires calling
Reader::computeHeader()
, butReader::getHeader()
does not invoke this method. As a result, the current sample code does not produce the expectedSyntaxError
.I have updated the sample code to use
getRecords()
, which correctly triggers theSyntaxError
for duplicate headers.Thanks.