Fixer to turn array_key_(first|last) into array_(first|last)
#9454
chriscpty
started this conversation in
Feature ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
PHP8.5 added
array_firstandarray_lastfunctions.Before this, we used
$array[array_key_first($array)]as a quick way to get the first/last element of an array a lot. A fixer to replace this overcomplicated syntax with the way simplerarray_first($array)would be cool.The rule could probably also turn
array_find(fn() => true)and similar "Usingarray_findto find the first element" calls intoarray_firsttoo.This would be a risky rule, as it does change the behavior slightly: The
array_key_firstlogic would throw an error when using it with an empty array, while thearray_firstlogic returns null instead.I'd be willing to give implementing this a shot if i get the OK from a maintainer👍
All reactions