Skip to content

Commit 628ac31

Browse files
committed
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: 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.
1 parent af7522b commit 628ac31

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
strategy:
4545
matrix:
46-
php: ['5.6', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
46+
php: ['7.1', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
4747

4848
runs-on: ubuntu-latest
4949

Mf2/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ public function upgradeRelTagToCategory(DOMElement $el) {
13831383
* @param DOMElement $context optionally specify an element from which to parse microformats
13841384
* @return array An array containing all the microformats found in the current document
13851385
*/
1386-
public function parse($convertClassic = true, DOMElement $context = null) {
1386+
public function parse($convertClassic = true, ?DOMElement $context = null) {
13871387
$this->convertClassic = $convertClassic;
13881388
$mfs = $this->parse_recursive($context);
13891389

@@ -1411,7 +1411,7 @@ public function parse($convertClassic = true, DOMElement $context = null) {
14111411
* @param int $depth: recursion depth
14121412
* @return array
14131413
*/
1414-
public function parse_recursive(DOMElement $context = null, $depth = 0) {
1414+
public function parse_recursive(?DOMElement $context = null, $depth = 0) {
14151415
$mfs = array();
14161416
$mfElements = $this->getRootMF($context);
14171417

@@ -1516,7 +1516,7 @@ public function parseFromId($id, $convertClassic=true) {
15161516
* @param DOMElement $context
15171517
* @return DOMNodeList
15181518
*/
1519-
public function getRootMF(DOMElement $context = null) {
1519+
public function getRootMF(?DOMElement $context = null) {
15201520
// start with mf2 root class name xpath
15211521
$xpaths = array(
15221522
'(php:function("\\Mf2\\classHasMf2RootClassname", normalize-space(@class)))'

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"bin": ["bin/fetch-mf2", "bin/parse-mf2"],
1313
"require": {
14-
"php": ">=5.6.0"
14+
"php": ">=7.1.0"
1515
},
1616
"config": {
1717
"platform": {

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
<description>PHP-MF2 Standards</description>
44
<file>./Mf2/Parser.php</file>
55
<rule ref="PHPCompatibility"/>
6-
<config name="testVersion" value="5.6-"/>
6+
<config name="testVersion" value="7.1-"/>
77
</ruleset>

0 commit comments

Comments
 (0)