Fix PHP 8.4 compatibility / drop support for PHP < 7.1 #264
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHP 8.4 deprecates implicitly nullable parameters, i.e. typed parameter with a
null
default value, which are not explicitly declared as nullable.Ref: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types
There are multiple ways to fix this, though most involve breaking changes:
As this is not a
final
class, nor are thesefinal
orprivate
methods, this would be a breaking change for any class extending theParser
class as parameter types are contra-variant, so this would cause a signature mismatch.null
default value.This, again, would be a breaking change and an even bigger one as it turns an optional parameter into a required one, so this wouldn't just have an impact on overloaded methods, but on all calls to the methods too.
This would not cause a signature mismatch.
This is the change with the least impact, although it does require PHP 7.1. If this is released as a next minor though, the impact will be minimal as Composer can handle the version negotiations and will just install an older version for PHP 5.6/7.0.
Also note that based on the Packagist stats, this version negotiation would rarely be needed as the users of this package hardly use PHP 5.6/7.0 anymore: https://packagist.org/packages/mf2/mf2/php-stats
With this in mind, I'm proposing dropping support for PHP < 7.1 and fixing the PHP 8.4 deprecations by making the relevant parameters explicitly nullable.
Includes updating CI and the PHPCS config.