php-mf2
php-mf2 copied to clipboard
Fix PHP 8.4 compatibility / drop support for PHP < 7.1
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:
- Remove the type declaration and do in-method type validation.
As this is not a
finalclass, nor are thesefinalorprivatemethods, this would be a breaking change for any class extending theParserclass as parameter types are contra-variant, so this would cause a signature mismatch. - Remove the
nulldefault 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. - Declare the parameters as nullable. 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.
FYI: once this PR has been merged (providing it is accepted), I have a commit ready to turn on testing on PHP 8.2/8.3/8.4 in CI.
Thanks for this PR! We're still discussing the best route forward. Historically we've kept PHP5.6 support around longer due to WordPress' extended support for it. We might work on some parsing updates, package one final release that supports PHP5.6, then move forward with 7.2+ only.
Historically we've kept PHP5.6 support around longer due to WordPress' extended support for it.
@gRegorLove Much appreciated! Just so you know, WP has dropped support for PHP < 7.2 in WP 6.6 (released July 2024), so doesn't have to be a blocker anymore ;-) (at least for this version bump)
Rebased without significant changes to get passed the merge conflict.
@gRegorLove If you are still unwilling to break PHP < 7.1, I prepared an alternative that works on full range of PHP versions. Though it is quite ugly and bypasses PHP ≥ 7.4’s contravariance checks.