League\Csv 8 and the Reader class

Attention: Les informations de ce billet sont susceptibles d'être obsolètes car vieux de plus 2 ans.

Warning: The information you are reading may be obsolete, this post was published more than 2 years ago.

League\Csv 8 has been officially released. This new major version requires at least PHP 5.5 and its corresponding HHVM version. Dropping support for PHP 5.4 makes the code significantly easier to maintain while enabling adding new functionalities. This version is focused on making the Reader class simpler as well as more flexible.

What’s new ?

This new version introduces two new extracting methods:

  • Reader::fetchPairs
  • Reader::fetchPairsWithoutDuplicates

With these additions, all basic retrieving methods that came to be expected from an extracting object are now available for you to use on any CSV document.

What’s changed ?

The Reader class has been rewritten to allow better CSV processing.

For that purpose methods that previously return array, namely, Reader::fetchAssoc and Reader::fetchColumn now return an Iterator. And their optional callable argument for are now easier to use by updating their parameter signature.

The query filter options used by the Reader class as well by the CSV conversion methods were reduced to those that where actually useful.

Because of inconsistencies between the Zend Engine and HHVM, the SplFileObject flags can no longer be set or modified.

Last but not least, small backward compatible breaks were introduced into the BOM API, to improve the methods return type consistencies.

Upgrading to the new version

If you’ve only use the Writer class, then upgrading should be simple as no changes was made to the class public API. If, on the other hand, you’ve been using the Reader class like always:

are there to help you upgrade your code.

Last but not least

Csv is an open source project with a MIT License so contributions are more than welcome and will be fully credited.  These contributions can be anything from reporting an issue, requesting or adding missing features or simply improving or correcting some typo on the documentation website.

One thought on “League\Csv 8 and the Reader class

Leave a Reply to mickmackusa Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.