Skip to content

Fix deprecation warning on PHP 8.5 - #81

Merged
SoftCreatR merged 3 commits into
SoftCreatR:mainfrom
mpesari:main
Nov 24, 2025
Merged

Fix deprecation warning on PHP 8.5#81
SoftCreatR merged 3 commits into
SoftCreatR:mainfrom
mpesari:main

Conversation

@mpesari

@mpesarimpesari commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

🔀 Pull Request

What does this PR do?

Fix deprecation warning when running unit tests on PHP 8.5.

This was the only warning that popped up.

Null coalescing operator ?? was added in PHP 7.0, so there are no backwards compatibility issues.

Test Plan

I enabled workflow to run tests on PHP 8.5.

Output before

$ php8.5 vendor/bin/phpunit --display-all-issues
PHPUnit 12.4.4 by Sebastian Bergmann and contributors.
Runtime: PHP 8.5.0
Configuration: /home/mpesari/git/SoftCreatR/JSONPath/phpunit.xml.dist
............................................................... 63 / 329 ( 19%)
............................................................... 126 / 329 ( 38%)
............................................................... 189 / 329 ( 57%)
.....................................................D......... 252 / 329 ( 76%)
............................................................... 315 / 329 ( 95%)
.............. 329 / 329 (100%)
Time: 00:00.051, Memory: 18.00 MB
1 test triggered 1 PHP deprecation:
1) /home/mpesari/git/SoftCreatR/JSONPath/src/AccessHelper.php:40
Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead
Triggered by:
* Flow\JSONPath\Test\QueryTest::testQueries#149 (4 times)
/home/mpesari/git/SoftCreatR/JSONPath/tests/QueryTest.php:42
OK, but there were issues!
Tests: 329, Assertions: 610, Deprecations: 1.

Output after

$ php8.5 vendor/bin/phpunit --display-all-issues
PHPUnit 12.4.4 by Sebastian Bergmann and contributors.
Runtime: PHP 8.5.0
Configuration: /home/mpesari/git/SoftCreatR/JSONPath/phpunit.xml.dist
............................................................... 63 / 329 ( 19%)
............................................................... 126 / 329 ( 38%)
............................................................... 189 / 329 ( 57%)
............................................................... 252 / 329 ( 76%)
............................................................... 315 / 329 ( 95%)
.............. 329 / 329 (100%)
Time: 00:00.052, Memory: 18.00 MB
OK (329 tests, 610 assertions)

Summary by CodeRabbit

  • Chores

    • Added PHP 8.5 to automated testing and compatibility metadata.
  • Bug Fixes

    • Adjusted collection lookup behavior so null keys are treated as an empty-string fallback.
  • Tests

    • Minor formatting cleanup in tests (no behavior changes).

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitaiBot commented Nov 24, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Adds PHP 8.5 to CI test matrix and changes AccessHelper::keyExists to treat null keys as empty strings when checking array keys.

Changes

Cohort / File(s)Summary
CI/CD Workflow Matrix
.github/workflows/Test.yml
Added 8.5 to the Test job's strategy.matrix.php list (now ['8.1','8.2','8.3','8.4','8.5']). No other workflow steps or conditional logic changed; continue-on-error still tied to 8.4.
Composer PHP Constraint
composer.json
Bumped PHP constraint range to include 8.5 ("8.1 - 8.5").
Array Key Lookup
src/AccessHelper.php
keyExists() now calls array_key_exists($key ?? '', $collection) instead of array_key_exists($key, $collection), mapping null keys to an empty string for array lookups.
Tests Formatting
tests/QueryTest.php
Minor whitespace change in a catch union type from `(JSONPathException

Sequence Diagram(s)

sequenceDiagram
participant Caller
participant AccessHelper
participant PHP_Array
Caller->>AccessHelper: keyExists(key)
alt key is null
AccessHelper->>AccessHelper: normalize key -> ($key ?? '')
Note right of AccessHelper `#E8F3FF`: converts null to empty string
AccessHelper->>PHP_Array: array_key_exists('', collection)
else key not null
AccessHelper->>PHP_Array: array_key_exists(key, collection)
end
PHP_Array-->>AccessHelper: boolean
AccessHelper-->>Caller: boolean
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review callers that may pass null to AccessHelper::keyExists to confirm null->empty-string behavior is intended.
  • Confirm CI addition of PHP 8.5 aligns with project support policy and that continue-on-error remaining tied to 8.4 is deliberate.

Poem

🐰 I hopped through lines of YAML bright,
Poked in eight-point-five to CI's light,
When keys were null I gave a shove,
Turned them empty, soft as love,
Small changes, joyful rabbit stuff. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title clearly and specifically describes the main change: fixing a PHP deprecation warning on PHP 8.5 by updating code in AccessHelper.php and supporting PHP 8.5 in CI/composer.json.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e2c450 and 18cbc1c.

📒 Files selected for processing (4)
  • .github/workflows/Test.yml (1 hunks)
  • composer.json (1 hunks)
  • src/AccessHelper.php (1 hunks)
  • tests/QueryTest.php (1 hunks)

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 and usage tips.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.84%. Comparing base (fc12dee) to head (2e2c450).
⚠️ Report is 34 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #81 +/- ##
============================================
+ Coverage 89.36% 89.84% +0.47% - Complexity 202 223 +21 
============================================
Files 11 11 Lines 395 443 +48 ============================================
+ Hits 353 398 +45 - Misses 42 45 +3 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/AccessHelper.php (1)

40-40: Fix is correct, but consider applying null guards consistently for code clarity.

The change at line 40 correctly addresses the PHP 8.5 deprecation of array_key_exists() with null keys. The verification confirms an inconsistency: while keyExists now guards against null with $key ?? '', the methods getValue (lines 73, 78), setValue (line 127), and unsetValue (line 141) access array keys directly without null guards.

This inconsistency is not functionally problematic—PHP implicitly converts null to empty string during direct array access, so the code will work correctly. However, for consistency and code clarity, these methods could also use the explicit null guard pattern when accessing arrays directly:

  • Line 73: $return = $collection[$key ?? ''];
  • Line 78: $return = $collection[$key ?? ''];
  • Line 127: return $collection[$key ?? ''] = $value;
  • Line 141: unset($collection[$key ?? '']);

This makes the null-handling behavior explicit and uniform across the class.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eee0a11 and 4416031.

📒 Files selected for processing (2)
  • .github/workflows/Test.yml (1 hunks)
  • src/AccessHelper.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/AccessHelper.php (1)
src/JSONPath.php (1)
  • key (224-227)
🔇 Additional comments (1)
.github/workflows/Test.yml (1)

26-27: PHP 8.5 added to test matrix successfully.

Adding PHP 8.5 to the test matrix is appropriate given the deprecation fix. The PR objectives confirm that tests pass on 8.5 after the changes.

Note that continue-on-error on line 27 is still tied only to PHP 8.4, not 8.5. This means failures on 8.5 will cause the workflow to fail. If PHP 8.5 is still experimental and failures should be tolerated, consider updating the condition to:

continue-on-error: ${{ matrix.php == '8.4' || matrix.php == '8.5' }}

Otherwise, the current configuration is correct if you want 8.5 to be treated as a stable, required version.

@SoftCreatRSoftCreatR added bug Something isn't working good first issue Good for newcomers labels Nov 24, 2025
@SoftCreatR

Copy link
Copy Markdown
Owner

Thanks :)

@SoftCreatR
SoftCreatR merged commit 09379ce into SoftCreatR:mainNov 24, 2025
0 of 7 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workinggood first issueGood for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@mpesari@codecov-commenter@SoftCreatR