flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.63k stars 407 forks source link

Deprecation exception with PHP 8 #454

Closed paxperscientiam closed 2 years ago

paxperscientiam commented 2 years ago

Hello!

After switching to PHP8.1, I am now getting a slew of deprecation errors, like this one:

Deprecated: Return type of flight\util\Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /<REDACTED>/vendor/mikecao/flight/flight/util/Collection.php on line 170

For the end-user, this is easy enough to work around by using the following command before requiring the library:

error_reporting(error_reporting() & ~E_DEPRECATED);

The fastest, least friendly way to address this would be to update composer.json to indicate that PHP compatibility is limited to >8.

The fastest, friendliest way to address this would be to slap a temporary warning in the readme, with the suggestion to use error_reporting(error_reporting() & ~E_DEPRECATED); temporarily.

Perhaps there's a way to specify a recommended PHP version range, and then to conditionally warn a user about the relevant deprecation issue?

OR, maybe the codebase alterations are trivial?

EDIT: PR #439 is relevant.

EDIT2:

Another relevant exception:

During inheritance of ArrayAccess: Uncaught ErrorException: Return type of flight\util\Collection::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /users/ramos/www/worth-the-weight/vendor/mikecao/flight/flight/util/Collection.php:106
masroore commented 2 years ago

Deprecation errors have been fixed in this PR: https://github.com/mikecao/flight/pull/439/commits/83fd1e75a2fcc6aecb180697512fe24fdbbe76e8

https://github.com/mikecao/flight/pull/439