fix(pick): resolve PHP 8 array offset warning on bool in validate() cache block - #7577
Open
faisalahammad wants to merge 2 commits into
Open
Conversation
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
PR Summary
|
Contributor
Author
|
AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me. |
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.
Description
In
classes/fields/pick.phpvalidate(), the bidirectional cache block at line 1871 was guarded only by! empty( $related_data ), not by whether$related_fieldis an actual field array. When the sister-field lookup fails (no matching sister id, related pod not the right type, etc.)$related_fieldstaysfalse, but$related_datamay 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
sister_idthat does not resolve to a matching pick field on Pod B.WP_DEBUGandWP_DEBUG_DISPLAYenabled, observe no PHP warnings.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