thephpleague / csv

CSV data manipulation made easy in PHP
https://csv.thephpleague.com
MIT License
3.34k stars 336 forks source link

Fatal error on second record fetch after dropping into PsySH repl #432

Closed Whalehunter closed 3 years ago

Whalehunter commented 3 years ago

Bug Report

Hello, maybe this is an error that should be reported to PsySH or PHP, but I have a problem when I'm trying to do some interactive code introspection with this library and PsySH.

Information Description
Version 9.7.1
PHP version 7.4.21
OS Platform Debian 4.19.194-2 (Linux 4.19.0-17-amd64)

Summary

When dropping into the eval(\Psy\sh()); after fetching some element from a ResultSet, the LimitIterator instance does not work anymore, with a PHP Fatal Error as a result: LogicException with message 'The object is in an invalid state as the parent constructor was not called'

Standalone code, or other way to reproduce the problem

require_once __DIR__.'/vendor/autoload.php';

$csv = League\Csv\Reader::createFromPath('some.csv');
$records = League\Csv\Statement::create()->process($csv);

$r = $records->fetchOne(1);
eval(\Psy\sh()); // Hit `ctrl+d` to exit repl.
$r = $records->fetchOne(2);
// Script crashes.

Expected result

It should not crash with a LogicException, since the fetchOne()-method explicitly calls the LimitIterator constructor.

Actual result

Example fatal error:

PHP Fatal error:  Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in /vendor/league/csv/src/ResultSet.php:166
Stack trace:
#0 [internal function]: LimitIterator->rewind()
#1 /vendor/league/csv/src/ResultSet.php(166): LimitIterator->rewind()
#2 /test.php(22): League\Csv\ResultSet->fetchOne()
#3 {main}
  thrown in /vendor/league/csv/src/ResultSet.php on line 166
nyamsprod commented 3 years ago

@Whalehunter thanks for using this package. I am not familiar with the PsySH library but the code your are using should indeed be working.

Does the issue exists if you remove the PsySH specific code 🤔. If the answer is no then most likely it is a PsySH issue.

Maybe try to reproduce the issue with as minimum as possible code to create a ticket on the PsySH issue tracker ... My 2 cents.

nyamsprod commented 3 years ago

@Whalehunter using your code without the PsySH instructions it works as intended. I will close this issue as the described behavior is not related to this package but to a third party tool

Whalehunter commented 3 years ago

Thanks for the quick reply! Indeed the code works as expected without PsySH in between. Thanks for the time and suggestion to report this issue to the PsySH maintainers, for some reason I hadn't thought of it as my first move.