PHP Warnings in ACF Integration
-
I am experiencing an issue with the Slim SEO – ACF Integration.
The PHP log file shows warnings: Undefined array key “…”
The issue is at line 16 of src/Integrations/ACF/Renderer.php
$field = $this->field_objects[ $name ] ?: null;
If $name does not exist as a key in $this->field_objects, PHP throws the warning.
(The key may not exist in cases where the ACF field has been added to an existing post type but not all posts have the field set)
Replacing the ternary shorthand (Elvis operator) with the null coalescing operator fixes the issue.
$field = $this->field_objects[ $name ] ?? null;
This safely checks for existence before accessing the array key and prevents the warning.
You must be logged in to reply to this topic.