Skip to content

fix: remove null array offsets from InputDataContainer - #21

Closed
csemazharul wants to merge 1 commit into
mainfrom
fix/null-array-offset-deprecation
Closed

csemazharul wants to merge 1 commit into
mainfrom
fix/null-array-offset-deprecation

Conversation

@csemazharul

Copy link
Copy Markdown
Collaborator

Closes #19

Problem

PHP 8.5 deprecates null as an array offset, including inside isset(). On 1.2.3, every Validator run hit this in InputDataContainer::getAttributeValue(), and the notice leaked into REST responses in Bit CRM. PHP 8.4 does not emit it, despite the issue title.

PR #20 fixed the main path with $key && isset($data[$key]), but two problems remained:

  • Remaining deprecations: reads and writes still used a null offset when no attribute key had been set.
  • Regression: $key && treats 0 and '0' as no key, so same:0 compared the field to itself and passed on a mismatch.

Changes

  • attributeKey now defaults to '', and setAttributeKey() turns null into ''. PHP already treated a null offset as '', so stored data is unchanged.
  • $key is checked with !== null, which restores falsy keys.
  • getAttributeValue() is flattened to early returns, with no behaviour change.
  • Added tests/InputDataContainerTest.php.
  • Minimum PHP version raised to 7.4 in composer.json, with rector.php and CLAUDE.md updated to match.

Before merging or releasing

  • Release as a minor version (1.3.0). Sites on PHP 7.2 or 7.3 stop receiving updates and stay on 1.2.4, which still has the same:0 bug.
  • getAttributeKey() now returns '' instead of null before a key is set. Nothing in src/ relies on null, but an outside caller checking === null would notice.

Testing

Check Result
PHP 8.4 tests 44 pass
PHP 8.5 tests 44 pass, 2 deprecations also present before this change; none traced to src/
New tests against unfixed src/ on PHP 8.5 6 of 8 fail, as expected
getAttributeValue() rewrite, old vs new 2,093 input combinations on PHP 8.5 and 7.4, no differences
PHP 7.4 Syntax check and repro script clean; Pest suite not run (Pest 2 needs PHP 8.1+)

The CI matrix stops at PHP 8.4, so CI does not exercise the PHP 8.5 deprecation. The new deprecation tests pass trivially on older versions.

Not addressed

same has two older bugs, also present in 1.2.3, which this PR leaves unchanged:

  • same:password passes when password is absent, because the lookup falls back to the field's own value.
  • On a nested field such as a.b, same:other compares the field to itself.

🤖 Generated with Claude Code

PHP 8.5 deprecates null as an array offset, including inside isset().
PR #20 guarded one read with `$key &&`, which left the unset attribute
key paths deprecated and made falsy keys fall through, so `same:0`
compared a field to itself and passed on a mismatch.

Keep attributeKey non-null and check $key with `!== null`. Flatten
getAttributeValue() to early returns.

Raise the minimum PHP version to 7.4 and update rector.php and
CLAUDE.md to match.

Closes #19

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@csemazharul csemazharul closed this Nov 2, 2026
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.

getAttributeValue() emits null-array-offset deprecation on PHP 8.4+

1 participant