Filina Consulting, Inc.

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!

Comments

txyoji March 24th, 2016 Anything that can create a segfault is probably a bug in php itself.
Looking forward to a post about your experience reporting this bug to the php community.
Anna April 1st, 2016 It's possible that there's a bug somewhere. However, to report it, I'd have to dig through Doctrine to see what exactly is causing it and I don't have that kind of time right now. Avoiding the issue by casting is easier.

Phone: +1 514-918-7866 | E-mail: me@afilina.com