Skip to content

Fix PHP 8.4 implicit nullable parameter deprecation (CMS-2804) - #376

Merged
fabianwgl merged 2 commits into
masterfrom
bugfix/CMS-2804-php84-nullable-deprecation
Sep 10, 2026
Merged

Fix PHP 8.4 implicit nullable parameter deprecation (CMS-2804)#376
fabianwgl merged 2 commits into
masterfrom
bugfix/CMS-2804-php84-nullable-deprecation

Conversation

@fabianwgl

@fabianwgl fabianwgl commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

User description

Summary

Fixes a PHP 8.4 deprecation warning reported by a customer on the WordPress.org support forum.

  • Class_Constant_Override_Validator_Trait::validate_required_array_class_constant() declared its second parameter as array $allowed_item_values = null, an implicitly nullable type.
  • PHP 8.4 deprecates implicit nullable parameter types (PHP RFC: Deprecate implicitly nullable parameter types).
  • Changed to ?array $allowed_item_values = null (explicit nullable type). No behavior change.

Checked the rest of src/ for the same pattern, this was the only occurrence.

Jira: CMS-2804

Test plan

  • Run the plugin's PHPUnit suite
  • Confirm no PHP 8.4 deprecation notice is emitted on a site running PHP 8.4

CodeAnt-AI Description

Prevent PHP 8.4 deprecation warnings for nullable array validation

What Changed

  • Explicitly allows the optional array of permitted values to be omitted or set to null
  • Removes the PHP 8.4 deprecation caused by the previous parameter declaration without changing validation behavior

Impact

✅ No PHP 8.4 nullable-parameter deprecation warnings
✅ Cleaner logs for supported PHP 8.4 sites

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

array $allowed_item_values = null is implicitly nullable, which PHP 8.4
deprecates. Use explicit ?array instead.
@codeant-ai

codeant-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 69a33bf Sep 08, 2026 · 09:01 09:03

@codeant-ai

codeant-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix PHP 8.4 nullable parameter deprecation

🐞 Bug fix 🕐 Less than 5 minutes

Grey Divider

AI Description

• Declares the optional allowed-values array as explicitly nullable.
• Prevents PHP 8.4 deprecation warnings without changing validation behavior.
High-Level Assessment

The explicit nullable array type is the optimal approach: it preserves the existing contract and default value while directly resolving PHP 8.4's implicit-nullability deprecation. Removing the type or changing the default would weaken typing or alter behavior.

Files changed (1) +1 / -1

Bug fix (1) +1 / -1
Class_Constant_Override_Validator_Trait.phpDeclare allowed values parameter as explicitly nullable +1/-1

Declare allowed values parameter as explicitly nullable

• Changes 'array $allowed_item_values = null' to '?array $allowed_item_values = null'. This removes the PHP 8.4 deprecation warning while preserving existing validation behavior and compatibility.

src/lib/traits/Class_Constant_Override_Validator_Trait.php

@qodo-code-review

qodo-code-review Bot commented Sep 8, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. PHP 5.6 and 7.0 sites cannot load the plugin ✓ Resolved 🐞 Bug ≡ Correctness
Description
The changed method declaration uses the ?array nullable type syntax, which is not supported by PHP
versions before 7.1. The CI matrix still tests PHP 5.6 and 7.0, so those installations fail during
PHP parsing before the plugin can initialize.
Code

src/lib/traits/Class_Constant_Override_Validator_Trait.php[124]

+	protected function validate_required_array_class_constant( $required_array_constant_name, ?array $allowed_item_values = null ) {
Evidence
The PR changes the method to ?array, while the repository's test workflow still includes PHP 7.0
and PHP 5.6. Those runtimes cannot parse nullable type declarations, causing a fatal syntax error
when the trait file is loaded.

src/lib/traits/Class_Constant_Override_Validator_Trait.php[124-124]
.github/workflows/test.yml[56-65]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The method now uses `?array`, which causes a parse error on the plugin's supported PHP 5.6 and PHP 7.0 runtimes. PHP 8.4 deprecation compatibility must be achieved without introducing syntax unavailable to those versions.

## Issue Context
The repository's CI matrix explicitly runs PHP 5.6 and PHP 7.0. Nullable parameter type declarations require PHP 7.1 or newer.

## Fix Focus Areas
- src/lib/traits/Class_Constant_Override_Validator_Trait.php[124-124]
- src/lib/traits/Class_Constant_Override_Validator_Trait.php[112-115]
- .github/workflows/test.yml[56-65]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: 🚀 Fast: A single localized type-annotation change addresses a PHP 8.4 deprecation without altering intended behavior or touching a high-risk area.

Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display preferences

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/lib/traits/Class_Constant_Override_Validator_Trait.php Outdated
@codeant-ai codeant-ai Bot added the size:XS This PR changes 0-9 lines, ignoring generated files label Sep 8, 2026
Comment thread src/lib/traits/Class_Constant_Override_Validator_Trait.php Outdated
?array requires PHP 7.1+ and breaks the PHP 5.6 and 7.0 CI jobs (this
plugin still declares Requires PHP: 5.6). Removing the type hint fixes
the PHP 8.4 deprecation without requiring a type hint syntax that isn't
available on all supported PHP versions. Runtime behavior is unchanged,
the two existing callers already only ever pass an array or omit the
argument.
@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

@apinto-uc apinto-uc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@fabianwgl
fabianwgl merged commit 5b86974 into master Sep 10, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants