thephpleague / csv

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

Fix PHP 8.1 deprecation errors #440

Closed cedric-anne closed 2 years ago

cedric-anne commented 2 years ago

Fixes following errors found running a test suite on PHP 8.1 RC3.

Adding the #[\ReturnTypeWillChange] attribute is the only way to prevent these warnings on current() methods without breaking compatibility with PHP < 8.0. For key() and valid() methods, we could add the return type instead of adding this attribute. I did not do it to prevent issues in inheritance chain, but then I saw these classes are final, so it could be a good solution too. Let me know if you want me to change this.

==> Error E_DEPRECATED in ./vendor/league/csv/src/Stream.php on line 384:
Return type of League\Csv\Stream::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
==> Error E_DEPRECATED in ./vendor/league/csv/src/Stream.php on line 324:
Return type of League\Csv\Stream::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
==> Error E_DEPRECATED in ./vendor/league/csv/src/Stream.php on line 368:
Return type of League\Csv\Stream::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
==> Error E_DEPRECATED in ./vendor/league/csv/src/MapIterator.php on line 45:
Return type of League\Csv\MapIterator::current() should either be compatible with IteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
cedric-anne commented 2 years ago

Hi @nyamsprod

I don't want to force your hand, but PHP 8.1.0 will be released on November 25th. I think a lot of people would like to be able to enjoy a stable release of league/csv, including these, fixes by then.

Regards

nyamsprod commented 2 years ago

@cedric-anne indeed but it seems that the PHP8.0 build is now broken 🤔 maybe have a look into it

nyamsprod commented 2 years ago

@cedric-anne seems the master already contains all the changes needed for PHP8.1 I just need some times to correctly prepare the 9.7.3 release. Hopefully it will be done next week

nyamsprod commented 2 years ago

9.7.3 has been released