My friends and family are under attack in Ukraine.
Donate to protect them directly or help international organizations.

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.

Context

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.

Debugging

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):

\Doctrine\Common\Util\Debug::dump($event);

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.

Solution

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.

Happy coding!

Previous: Testing Methods That Make Static Calls Next: Experience With Immigration Fraud