- 
                Notifications
    You must be signed in to change notification settings 
- Fork 11.6k
[12.x] Fix PHP 8.5 null-key deprecations #57137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| $keys = is_array($key) ? $key : func_get_args(); | ||
|  | ||
| return array_all($keys, fn ($key) => array_key_exists($key, $this->items)); | ||
| return array_all($keys, fn ($key) => array_key_exists($key ?? '', $this->items)); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to consider null to be ''? If we have an array containing an item with '', it will be returned, when null is given, which can be unintentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using null as key currently has the same behaviour (PHP 8.4):
> $arr[null] = 'test'
= "test"
> $arr
= [
    "" => "test",
  ]
> $arr['']
= "test"
When it comes to Collection and Arr, I'm a bit on the fence. We can either silently cast it to string for the users to keep things working as before, or let the deprecation be triggered and expect an userland logic change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation 👍🏻
| I mean, TKey is defined as  | 
| @donnysim I agree, however this test suggests we could still use  framework/tests/Support/SupportCollectionTest.php Lines 5544 to 5549 in 559976f 
 I could imagine many users having  I also noticed that  | 
* Fix PHP 8.5 null-key deprecations * Fix getOrPut * Update InteractsWithIO.php * Update Collection.php --------- Co-authored-by: Taylor Otwell <[email protected]>
PHP 8.5 deprecates using
nullas array key (accessing, setting, as well as things likearray_key_exists()):I have personally encountered this deprecation in
parseVerbosity()as usually it's set tonullwhen calling$this->line('message'). Other places were discovered by running the test suite. Please note that most likely not all occurrences were found yet.