Fix PHP 8.4 implicit nullable deprecation in Formatter\Links - #477
Open
mohsenny wants to merge 1 commit into
Open
Fix PHP 8.4 implicit nullable deprecation in Formatter\Links#477mohsenny wants to merge 1 commit into
mohsenny wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix PHP 8.4 implicit nullable deprecation in
Formatter\LinksHi, 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()declaresarray $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.Why this is the right fix
Null is clearly intended here, and the surrounding code already says so:
private ?array $internal_domains;?string $filter_by = nullSo 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
After
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, atclasses/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"incomposer.json), so the minimum supported version is unaffected.