[PHP8.5 compat] fix: array null key access is deprecated #90
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Hi Frank and Team,
After upgrading our services to run on PHP 8.5 we started getting deprecation warnings originating from
ObjectHydrator.The problem seems to be that this line
is_array($value[array_key_first($value)] ?? false))can receive an empty array as first parameter,array_key_firstreturnsnullin that case, and this has been deprecated in PHP 8.5The way we fixed it in this PR is by checking if the array is empty before attempting any key access, that fixed it in our case.
Currently the test suite does not fail on PHP 8.5, so I have added a test (happy and sad path) to verify this behavior, before fixing it.
I am not sure if the null-coalesce is still required, I think it was originally their to handle the
nullreturn from thearray_key_first, I left it for now, but let me know if you feel like it should be removedGr Sven