Doctrine: String keys with Array hydration
- by BenV
According to their documentation, you should use Array hydration rather than record hydration when retrieving data for read-only purposes.
However, this means I have to access the attributes of the retrieved object using arrays and string keys:
$user['Phonenumbers'][0]['number']
instead of the OO style:
$user->PhoneNumbers[0]->number
Now I'm kinda new to PHP, but in other languages I've worked with the 2nd notation would be preferable because typos would be caught at compile time while typos in string literals would not be noticed until runtime. Does this apply to PHP/Doctrine?