php-mf2 icon indicating copy to clipboard operation
php-mf2 copied to clipboard

Fix PHP 8.4 compatibility / drop support for PHP < 7.1

Open jrfnl opened this issue 1 year ago • 4 comments

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:

  1. Remove the type declaration and do in-method type validation. As this is not a final class, nor are these final or private methods, this would be a breaking change for any class extending the Parser class as parameter types are contra-variant, so this would cause a signature mismatch.
  2. Remove the 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.
  3. 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.

jrfnl avatar Sep 12 '24 04:09 jrfnl

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.

jrfnl avatar Sep 12 '24 04:09 jrfnl

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.

gRegorLove avatar Sep 30 '24 02:09 gRegorLove

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)

jrfnl avatar Sep 30 '24 03:09 jrfnl

Rebased without significant changes to get passed the merge conflict.

jrfnl avatar May 28 '25 20:05 jrfnl

@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.

jtojnar avatar Jun 28 '25 11:06 jtojnar