dbal icon indicating copy to clipboard operation
dbal copied to clipboard

Documentation about simple_array type suggests it can return null, an empty array is returned instead

Open holtkamp opened this issue 4 months ago • 4 comments

https://github.com/doctrine/dbal/blob/4.3.x/docs/en/reference/types.rst#simple_array https://github.com/doctrine/dbal/blob/4.4.x/docs/en/reference/types.rst#simple_array https://github.com/doctrine/dbal/blob/5.0.x/docs/en/reference/types.rst#simple_array

all end with:

Values retrieved from the database are always converted to PHP's array type using comma delimited explode() or null if no data is present.

The last sentence "or null if no data is present." seems not the way it is implemented: in case no data is present, an empty array is returned according to:

https://github.com/doctrine/dbal/blob/4.3.x/src/Types/SimpleArrayType.php#L43-L45

To me that seems incorrect. An empty array is a different value than NULL. NULL is no value. Why isn't NULL returned as the documentations states? And if the current implementation is the "agreed upon approach", then the documentation should be changed to indicate an array is always returned?

holtkamp avatar Aug 21 '25 18:08 holtkamp

It would be interesting to take a look at the git history.

greg0ire avatar Aug 26 '25 13:08 greg0ire

It would be interesting to take a look at the git history.

I did and it seems it has always been this way for over a decade. And tbh, I don't think this issue is worth fixing. I'd rather remove that broken type entirely.

derrabus avatar Sep 04 '25 21:09 derrabus

@derrabus

I'd rather remove that broken type entirely.

Do you mean that the documentation should be updated and a "NULL" value in the database would result in an empty array in PHP?

Note that in the documentation https://github.com/doctrine/dbal/blob/5.0.x/docs/en/reference/types.rst the phrase "or null if no data is present." occurs 22 times, so it is used a lot. Not using it for an array would mean an inconsistency...

Would it not be better to prevent inconsistencies and start returning NULL in the next major version as a backward incompatible change?

holtkamp avatar Sep 09 '25 09:09 holtkamp

Would it not be better to prevent inconsistencies and start returning NULL in the next major version as a backward incompatible change?

No. That's a super subtle change that will break old apps for no reason. If we removed the type, any app that still uses it could simply fork it before upgrading to the next major. I did this in various projects with the "array" type, for example.

derrabus avatar Sep 09 '25 18:09 derrabus