Skip to content

Conversation

@SavageTiger
Copy link

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_first returns null in that case, and this has been deprecated in PHP 8.5

The 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 null return from the array_key_first, I left it for now, but let me know if you feel like it should be removed

Gr Sven

When an object was hydrated using a typehint docblock it can happen that it tries to check if the sub-array key exists in order to know if it should traverse further down the object tree.

When an object is hydrated using a type-hinted docblock, it may attempt to check whether a sub-array key exists in order to determine if it should traverse further down the object tree.

Previously, this check relied on the null-coalesce operator to fall back to false. However, when the array is empty, array_key_first() returns null, and accessing a null offset is deprecated as of PHP 8.5. To address this, we added a count() check to detect empty arrays.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant