Skip to content

[13.x] Solve another PHP 8.5 null index deprecation - #60964

Merged
taylorotwell merged 3 commits into
laravel:13.xfrom
tontonsb:patch-38
Aug 2, 2026
Merged

[13.x] Solve another PHP 8.5 null index deprecation#60964
taylorotwell merged 3 commits into
laravel:13.xfrom
tontonsb:patch-38

Conversation

@tontonsb

Copy link
Copy Markdown
Contributor

There have been a few fixes already. On two cases I'm still encountering warnings:

  • $collection->keyBy('someKey') emits a warning if some values in someKey are null.
  • $collection[$offset] emits a warning if $offset = null.

I propose to solve the Collection::keyBy issue by doing a cast to string (effectively replacing it with an empty string) because that's

I think it should be solved in framework for convenience, backwards compatibility and parity with the Collection::groupBy behaviour. I am also adding a simple test for both keyBy and groupBy to make this behaviour more locked in.

What about $collection[$offset]?

That warning is easier to solve on your own and it forces you to focus the attention on auto-cast in exactly the way that the warning was intended to do. So I haven't tried to solve it yet. But I've done some research:

  • collect(['a' => 1, '' => 3])->has(null) is true
  • collect(['a' => 1, '' => 3])->get(null) returns 3
  • collect(['a' => 1, '' => 3])[null­] returns 3 and emits the warning

So maybe we should make ->get(null) and [null] work the same while we're at it? Is dropping the warning the correct direction here?

By the way

  • Arr::exists(['a' => 1, '' => 3], null) is true
  • Arr::has(['a' => 1, '' => 3], null) is false 🙃
  • Arr::get(['a' => 1, '' => 3], null) returns ['a' => 1, '' => 3] (the whole array)

@taylorotwell
taylorotwell merged commit 577de0e into laravel:13.x Aug 2, 2026
44 of 54 checks passed
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