-1

Since we will just be storing short simple strings here, why is it presented as the default option when we could be using a simpler simple_array? Is it just a matter of preferences?

yhu420
  • 436
  • 6
  • 18

1 Answers1

1

My wild guess would be:

simple_array uses simple explode/implode to deserialize/serialize data, which does not offer any sort of escaping of a comma.

Example:

$arr = ["some,foo","and","another","bar"]; // Notice that the first string contains ",". 

echo implode(',', $arr);

This produces some,foo,and,another,bar, but notice exploding would produce array of 5 elements (not 4):

["some","foo","and","another","bar"]

This would clearly produce invalid behavior in the app.

There was a feature request opened a couple of years ago about this, but it was closed exactly in favor of using the JSON type: https://github.com/doctrine/dbal/issues/3300

Jovan Perovic
  • 19,846
  • 5
  • 44
  • 85
  • 2
    Pretty sure json is the default because most databases now support it as a native column type. Array and simple_array are just text types and mean nothing outside of Doctrine. – Cerad Mar 12 '21 at 13:24
  • IMO, CSV is still a valid and widely accepted data format and does have a meaning outside of Doctrine. However, for the `array` type I agree. For me, it has no real value not only outside of Doctrine but PHP as well... (in terms of managing data by hand) – Jovan Perovic Mar 12 '21 at 13:50
  • 1
    CSV has a meaning at the database table level but I am not aware of any major database engine that understands CSV as a column type. This is in contrast to json where, for example, you can query against individual json attributes in a reasonably efficient way should the need arise. – Cerad Mar 12 '21 at 14:28