Fixing Doctrine Segfaults
March 21st, 2016
I had a tricky segfault when trying to save a very simple Doctrine object. Here's my debugging process and solution.
I was using the sabre/vobject package to parse and save some iCal data. The parsed data was assigned to properties of a Doctrine entity and then persisted. The segmentation fault was happening every single time I called the entity manager's flush() method.
After reading this answer on StackOverflow, I started to wonder whether something was wrong with the contents of the entity. So I used this utility method to inspect it (don't just var_dump as you'll get too much output):
What did I see? Instead of being a simple string, the summary was a Sabre\VObject\Property\FlatText. Obviously Doctrine wasn't able to deal with that type and something exploded in the process.
The solution was really simple. Just cast the property to string before assigning:
$event->summary = (string)vobject->SUMMARY;
This is a good reminder to double-check your entities before persisting them, especially when you get data from libraries with which you're not quite familiar.