Skip to content

fix: PHP 8.5 "Using null as an array offset" deprecation in RW - #111

Merged
Vitexus merged 1 commit into
Spoje-NET:mainfrom
fesak001:fix/php85-null-array-offset
Jul 28, 2026
Merged

fix: PHP 8.5 "Using null as an array offset" deprecation in RW#111
Vitexus merged 1 commit into
Spoje-NET:mainfrom
fesak001:fix/php85-null-array-offset

Conversation

@fesak001

@fesak001 fesak001 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

PHP 8.5 deprecates using null as an array offset (Using null as an array offset is deprecated, use an empty string instead). The deprecation is emitted for writes, reads, isset() and ?? alike.

Two places in RW.php use a possibly-null value as an array key:

  1. extractResultIDs() sets $extid = null when an insert result carries no request-id, then writes $candidates[$evidence][$extid]. We hit this in production on PHP 8.5.8 (hundreds of log entries per day when inserting invoices).
  2. assignResultIDs() uses $chained->getRecordID() as a lookup key, and getRecordID() may return null.

Since PHP has always coerced a null offset to '' (which is exactly what the deprecation message suggests), replacing null with '' keeps the behavior identical on all PHP versions, including the interplay between the two methods (a record inserted without request-id is still found under the same key).

Also implements the previously stubbed testextractResultIDs() to cover both branches (with and without request-id).

Tested with PHPUnit on PHP 8.5.8, php-cs-fixer clean.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of missing external request IDs during result processing.
    • Ensured records without a request ID are matched consistently instead of producing null-based results.
  • Tests

    • Added coverage for result extraction, including records with and without external request IDs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

RW now converts missing chained and request-derived external IDs to empty strings, and a PHPUnit test verifies extraction output for entries with and without request-id.

Changes

External ID normalization

Layer / File(s) Summary
Normalize and test external ID keys
src/AbraFlexi/RW.php, tests/src/AbraFlexi/RWTest.php
assignResultIDs() and extractResultIDs() use empty strings for missing external IDs; PHPUnit coverage verifies the grouped extraction result.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing the PHP 8.5 null array offset deprecation in RW.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/AbraFlexi/RW.php (1)

214-214: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for the null chained-ID path.

The new null-to-'' behavior in assignResultIDs() is not covered by the added test. Add a PHPUnit case where getRecordID() returns null and verify that the chained object is matched through the empty-string candidate key.

As per coding guidelines, updated classes should include applicable PHPUnit coverage and be well-tested.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/AbraFlexi/RW.php` at line 214, Add PHPUnit regression coverage for
assignResultIDs() where chained->getRecordID() returns null, asserting the
chained object is matched using the empty-string candidate key. Reuse the
existing test fixtures and expectations for chained ID assignment, changing only
the ID setup needed to exercise the null-to-empty-string path.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/AbraFlexi/RW.php`:
- Around line 253-257: Normalize both missing and explicitly null request IDs to
an empty string in the $extid assignment within src/AbraFlexi/RW.php lines
253-260, using null coalescing or an equivalent null check. Add coverage in
tests/src/AbraFlexi/RWTest.php lines 108-123 for an upstream response with
request-id set to null, verifying it is grouped under the empty-string key.

---

Nitpick comments:
In `@src/AbraFlexi/RW.php`:
- Line 214: Add PHPUnit regression coverage for assignResultIDs() where
chained->getRecordID() returns null, asserting the chained object is matched
using the empty-string candidate key. Reuse the existing test fixtures and
expectations for chained ID assignment, changing only the ID setup needed to
exercise the null-to-empty-string path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c8694af-4f21-4af0-a188-fb2fd3ae2dd5

📥 Commits

Reviewing files that changed from the base of the PR and between 6ee3bcb and b9b798a.

📒 Files selected for processing (2)
  • src/AbraFlexi/RW.php
  • tests/src/AbraFlexi/RWTest.php

Comment thread src/AbraFlexi/RW.php
@Vitexus
Vitexus merged commit 875dd72 into Spoje-NET:main Jul 28, 2026
2 checks passed
@Vitexus

Vitexus commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

@fesak001 Thank you for your Fable tokens! :D

image

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.

2 participants