Skip to content

fix(pick): resolve PHP 8 array offset warning on bool in validate() cache block - #7577

Open
faisalahammad wants to merge 2 commits into
pods-framework:release/3.4.0from
faisalahammad:fix/7244-pick-validate-bool-array-offset
Open

fix(pick): resolve PHP 8 array offset warning on bool in validate() cache block#7577
faisalahammad wants to merge 2 commits into
pods-framework:release/3.4.0from
faisalahammad:fix/7244-pick-validate-bool-array-offset

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Description

In classes/fields/pick.php validate(), the bidirectional cache block at line 1871 was guarded only by ! empty( $related_data ), not by whether $related_field is an actual field array. When the sister-field lookup fails (no matching sister id, related pod not the right type, etc.) $related_field stays false, but $related_data may be non-empty from a prior cache hit. The block then dereferences $related_field['id'] and $related_field['name'], producing the PHP 8.0+ warnings reported in #7244.

This was reported when saving a Pod through Gravity Forms. The save itself succeeds, but PHP raises warnings on each invocation.

Related GitHub issue(s)

Fixes #7244

Testing instructions

  1. Create Pod A with a pick field pointing to Pod B and a sister_id that does not resolve to a matching pick field on Pod B.
  2. Submit a Gravity Form that creates/edits a Pod A entry through the Pods GF add-on.
  3. With WP_DEBUG and WP_DEBUG_DISPLAY enabled, observe no PHP warnings.
  4. Confirm the entry saves correctly.

A manual regression (positive case) on a fully configured bidirectional relationship still works as before: the cache block now skips when sister lookup fails, and save() already guards separately before dereferencing the cache at line 2001.

Pull Request Checklist

  • I have tested my own code to confirm it works as I intended.
  • My code follows the WordPress Coding Standards.
  • My code follows the WordPress Inline Documentation Standards.
  • My code includes automated tests for PHP and/or JS (if applicable).

In validate(), the cache block at line 1871 only checks `! empty( $related_data )`
but does not verify $related_field is an array. When the sister field
lookup fails, $related_field stays false and the block then dereferences
$related_field['id'] / $related_field['name'], producing PHP 8.0+
"Accessing array offset on value of type bool" warnings reported in
pods-framework#7244 (Pod save through Gravity Forms).

Add `! empty( $related_field )` to the guard so the block only runs
when related_field is a real field array. The save() method already
guards separately on line 2001, so this is a single-file change.

Fixes pods-framework#7244
@what-the-diff

what-the-diff Bot commented Jul 26, 2026

Copy link
Copy Markdown

PR Summary

  • Improved Validation for Related Data Processing
    The conditions for validating related data have been upgraded to ensure both the related data ($related_data) and related field ($related_field) are present before proceeding. This helps minimize errors and inefficiencies during data processing.

@faisalahammad
faisalahammad changed the base branch from main to release/3.4.0 August 18, 2026 11:33
@faisalahammad

Copy link
Copy Markdown
Contributor Author

AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me.

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.

Warning: Trying to access array offset on value of type bool in pick.php on line 1846

1 participant