-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
TabularDataReader::getRecords()->current() can return NULL #514
Comments
@josefsabl thanks for using the library. To me what you are experiencing/describing is not a bug but rather an undocumented and unsupported way of using the package. The method is expected to be used either with a To me the documented way of doing what you were expecting is as follow: <?php
use League\Csv\Reader;
use League\Csv\Statement;
var_dump(
$records = Statement::create()
->process(
Reader::createFromString('hello;world')
->setDelimiter(';')
)
- ->getRecords()
- ->current()
+ ->first()
); You may use Using |
@josefsabl after consideration a quick fix was added to correct the behaviour. What you are experiencing is due to how PHP handles iterator. <?php
$records = Statement::create()
->process(
Reader::createFromString('hello;world')
->setDelimiter(';')
)
->getRecords();
+ $records->rewind();
$records->current(); When used via |
@josefsabl After much consideration I've decided to go along the POLA principle aka Principle Of Least Astonishment. This means that I will not consider the current ticket as it being a bug but rather the expected behaviour in PHP language. So there's no need to wait for the next minor version for fixing this behaviour. Currently to align with PHP behaviour you only have 2 possibilities. Those I gave you in response to this ticket:
|
Bug Report
Summary
In 9.12.0 the
\League\Csv\Statement::create()->process('...')->getRecords()->current()
started to return NULL even if the records is not empty.Iterating over iterator works as expected.
Standalone code, or other way to reproduce the problem
Expected result
Version <9.11.0 prints:
Actual result
Version >=9.12.0 (including master) prints:
Checks before submitting
The text was updated successfully, but these errors were encountered: