Skip to content

Fix 'using null as an array offset is deprecated' on PHP 8.5 - #13

Merged
vasa-c merged 1 commit into
axypro:masterfrom
imorland:fix-null-array-offset-php85
Aug 5, 2026
Merged

Fix 'using null as an array offset is deprecated' on PHP 8.5#13
vasa-c merged 1 commit into
axypro:masterfrom
imorland:fix-null-array-offset-php85

Conversation

@imorland

@imorland imorland commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Line::concat() tests the array before it tests the index:

$fi = $source->fileIndex;
$ni = $source->nameIndex;
if ((isset($mSources[$fi])) && ($fi !== null)) {
    $source->fileIndex = $mSources[$fi];
}
if ((isset($mNames[$ni])) && ($ni !== null)) {
    $source->nameIndex = $mNames[$ni];
}

isset($mSources[$fi]) evaluates the offset first, so with $fi null the $fi !== null check is never reached — it can't do anything. $fi and $ni are null whenever a position has no source file or no name, which is routine, and PHP 8.5 reports every occurrence:

PHP Deprecated:  Using null as an array offset is deprecated, use an empty string instead in src/parsing/Line.php on line 495

Swapping the operands can't change behaviour, since isset() on a null offset is already false.

I found this in Flarum, where we concatenate a sourcemap per asset when building the frontend bundle. On a debug install with display_errors on it's hundreds of lines per request — flarum/framework#4894 has the detail.

Checks

  • Test suite passes on 8.1, 8.2, 8.3, 8.4 and 8.5 — 147 tests, 387 assertions.
  • concat() output is byte-identical before and after, same input.
  • No deprecations left in src on 8.5. The 7 that remain are all in axy/errors and axy/codecs-base64vlq, which I've mentioned in the issue.
  • phpcs clean.

Closes #12

In Line::concat() the two guards test the array before testing the index:

    if ((isset($mSources[$fi])) && ($fi !== null)) {

`isset($mSources[$fi])` evaluates the offset first, so `$fi !== null` is
never reached with $fi null and the null check is unreachable. $fi and $ni
are null whenever a position has no source file or no name, which is
routine, and PHP 8.5 reports each occurrence.

Swapping the operands cannot change behaviour, since isset() on a null
offset is already false. Verified on 8.5: concat() output is byte-identical
before and after, and the test suite passes on 8.1 through 8.5.
@imorland
imorland force-pushed the fix-null-array-offset-php85 branch from 049caf0 to 43054d1 Compare August 5, 2026 11:45
@vasa-c
vasa-c merged commit d1ad0fa into axypro:master Aug 5, 2026
imorland added a commit to flarum/framework that referenced this pull request Aug 5, 2026
…on fix (#4904)

`axy/sourcemap` 1.1.1 reorders the two guards in `Line::concat()` that read an
array before checking the index is not null, which PHP 8.5 reports once per
mapped position — hundreds of lines per request while compiling assets on a
debug install (#4894, fixed upstream in axypro/sourcemap#13).

`^1.1` already resolved to it, so this changes nothing for a fresh install. It
is here to say so: the version we need is 1.1.1, not merely whatever 1.x
resolves to today.

Verified on PHP 8.5 that `JsCompiler`'s concat path no longer emits the notice,
with byte-identical sourcemap output.
imorland added a commit to flarum/flarum-core that referenced this pull request Aug 5, 2026
…on fix (#4904)

`axy/sourcemap` 1.1.1 reorders the two guards in `Line::concat()` that read an
array before checking the index is not null, which PHP 8.5 reports once per
mapped position — hundreds of lines per request while compiling assets on a
debug install (#4894, fixed upstream in axypro/sourcemap#13).

`^1.1` already resolved to it, so this changes nothing for a fresh install. It
is here to say so: the version we need is 1.1.1, not merely whatever 1.x
resolves to today.

Verified on PHP 8.5 that `JsCompiler`'s concat path no longer emits the notice,
with byte-identical sourcemap output.
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.

Using null as an array offset is deprecated on PHP 8.5

2 participants