Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/traits/Class_Constant_Override_Validator_Trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function validate_required_array_class_constants( array $required_arra
*
* @throws Exception
*/
protected function validate_required_array_class_constant( $required_array_constant_name, array $allowed_item_values = null ) {
protected function validate_required_array_class_constant( $required_array_constant_name, ?array $allowed_item_values = null ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Php <7.1 parse error 🐞 Bug ☼ Reliability

validate_required_array_class_constant() now uses ?array, which is PHP 7.1+ syntax and will fail
to parse on PHP 5.6/7.0, preventing the plugin from loading at all. This bypasses the plugin’s
runtime minimum-PHP check because the file can’t be parsed first.
Agent Prompt
## Issue description
The PR introduces a nullable array type hint (`?array`) which is not supported in PHP versions below 7.1. The plugin declares support for PHP 5.6, so this will cause a parse error before any runtime compatibility checks execute.

## Issue Context
The parameter already defaults to `null`, so PHP 5.6-compatible options include keeping the old signature (`array $allowed_item_values = null`) and relying on the phpdoc `@param array|null`, or removing the type hint and validating with `is_array()` when non-null.

## Fix Focus Areas
- src/lib/traits/Class_Constant_Override_Validator_Trait.php[118-152]
- readme.txt[1-10]
- src/lib/Cookiebot_WP.php[23-92]

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: This nullable type declaration requires PHP 7.1+, but the plugin declares support for PHP 5.6; on supported 5.6 installs this file will fail to parse and can break plugin loading before runtime version checks execute. Keep the parameter untyped (or use a PHP-5.6-compatible approach) to preserve the documented minimum PHP compatibility. [api mismatch]

Severity Level: Critical 🚨
- ❌ Plugin crashes on PHP 5.6 during addon autoload.
- ❌ Cookiebot_WP PHP version guard never runs on 5.6.
- ⚠️ WordPress admin cannot safely deactivate failing plugin.
Steps of Reproduction ✅
1. Confirm the plugin advertises PHP 5.6 support: `readme.txt` lines 4–7 show “* Requires
PHP: 5.6”, and `src/lib/Cookiebot_WP.php` defines `const COOKIEBOT_MIN_PHP_VERSION =
'5.6.0';` around lines 5–6 (verified via Grep).

2. On a WordPress site running PHP 5.6, install and activate this plugin so WordPress
loads `cookiebot.php` (lines 1–24) which defines plugin constants, then `require_once`
includes `vendor/autoload.php`, `src/lib/helper.php`, and
`src/lib/global-deprecations.php`, and finally calls `\cybot\cookiebot\lib\cookiebot()` at
`cookiebot.php:26`.

3. In `src/lib/helper.php`, the namespaced `cookiebot()` function (around lines 10–18 and
620–637) returns `Cookiebot_WP::instance()`, whose constructor in
`src/lib/Cookiebot_WP.php` immediately calls
`throw_exception_if_php_version_is_incompatible()` and then `cookiebot_init()`, where
`Cookiebot_Addons::instance()` is invoked (seen in `src/lib/Cookiebot_WP.php` around lines
25–37).

4. `Cookiebot_Addons::__construct()` in `src/addons/Cookiebot_Addons.php` (lines 60–94 and
120–140) builds a container that instantiates `Settings_Service`
(`src/lib/Settings_Service.php:5`), which `use`s
`cybot\cookiebot\addons\controller\addons\Base_Cookiebot_Addon`; Composer’s PSR-4
autoloader then loads `src/addons/controller/addons/Base_Cookiebot_Addon.php`, which in
turn `use`s `cybot\cookiebot\lib\traits\Class_Constant_Override_Validator_Trait` and
`use`s the trait at line 19, triggering inclusion of
`src/lib/traits/Class_Constant_Override_Validator_Trait.php` where
`validate_required_array_class_constant( $required_array_constant_name, ?array
$allowed_item_values = null )` is declared (line 25 in the snippet). On PHP 5.6 this
nullable `?array` parameter is invalid syntax, causing a fatal “unexpected '?'” parse
error at load time before `Cookiebot_WP::throw_exception_if_php_version_is_incompatible()`
can run, breaking plugin initialization on an environment the plugin claims to support.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/lib/traits/Class_Constant_Override_Validator_Trait.php
**Line:** 124:124
**Comment:**
	*Api Mismatch: This nullable type declaration requires PHP 7.1+, but the plugin declares support for PHP 5.6; on supported 5.6 installs this file will fail to parse and can break plugin loading before runtime version checks execute. Keep the parameter untyped (or use a PHP-5.6-compatible approach) to preserve the documented minimum PHP compatibility.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

if ( ! is_string( $required_array_constant_name ) ) {
throw new InvalidArgumentException();
}
Expand Down