Skip to content

Fix PHP 8.4 implicit nullable deprecation in Formatter\Links - #477

Open
mohsenny wants to merge 1 commit into
codepress:mainfrom
mohsenny:fix/php84-implicit-nullable
Open

Fix PHP 8.4 implicit nullable deprecation in Formatter\Links#477
mohsenny wants to merge 1 commit into
codepress:mainfrom
mohsenny:fix/php84-implicit-nullable

Conversation

@mohsenny

Copy link
Copy Markdown

Fix PHP 8.4 implicit nullable deprecation in Formatter\Links

Hi, I'm Mohsen, a QA lead based in Berlin. I have no commercial stake in this plugin. I was linting a sample of plugins from the .org directory against PHP 8.5 to see how the ecosystem is holding up ahead of the next round of host upgrades, this one came up, and the fix is small enough that a patch seemed more useful than an issue.

Worth saying plainly given what the ecosystem has been through this year: I prepared this with AI assistance, which is what the co-author trailer on the commit is for. I checked every claim below myself against a real PHP 8.5.10 build. The change is one line in one file, and it touches no behaviour. If you would rather not take patches from outside, no problem at all, just close it.

What

AC\Formatter\Links::__construct() declares array $internal_domains = null. PHP 8.4 deprecated implicitly nullable parameter types, so this emits a deprecation notice whenever the class is loaded on PHP 8.4 or newer.

// classes/Formatter/Links.php:19
- public function __construct(?string $filter_by = null, array $internal_domains = null)
+ public function __construct(?string $filter_by = null, ?array $internal_domains = null)

Why this is the right fix

Null is clearly intended here, and the surrounding code already says so:

  • the backing property is declared private ?array $internal_domains;
  • the first parameter on the same signature already uses ?string $filter_by = null

So this only makes the second parameter consistent with the property it assigns to and with its own neighbour. Behaviour is unchanged.

Verification

Against PHP 8.5.10 (CLI), using php -l, which reports compile-time deprecations:

Before

PHP Deprecated:  AC\Formatter\Links::__construct(): Implicitly marking parameter
$internal_domains as nullable is deprecated, the explicit nullable type must be
used instead in classes/Formatter/Links.php on line 19

After

No syntax errors detected in classes/Formatter/Links.php

PHPCompatibility (dev-develop, testVersion 8.4-) also reported this file clean after the change.

This is not only on main: the same notice is present in the released 7.0.19 build from wordpress.org, at classes/Formatter/Links.php:20.

Compatibility

Nullable type syntax (?array) has been available since PHP 7.1. This plugin requires PHP 7.4 (Requires PHP: 7.4, and "php": "7.4.33" in composer.json), so the minimum supported version is unaffected.

PHP 8.4 deprecates implicitly nullable parameter types. The
$internal_domains parameter defaults to null but is typed `array`,
which emits a deprecation notice on PHP 8.4+.

The backing property is already declared `?array`, and $filter_by on
the same signature already uses `?string`, so this makes the second
parameter consistent with both.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant