Archive for the ‘PHP’ Category
Serialization issues with SimpleXML
I’m using PHP for my semester project @ EPFL, and I stumbled upon a curious bug when trying to serialize an object (using PHP’s serialize()):
Node no longer exists
First I thought it was because of an infinite recursive loop (object A contains object B who in turn contains object A again, and so on), but in fact, infinite recursivity is allowed with serialize()!
Therefore, the problem was elsewhere: it ended up being an issue with SimpleXML, as explained here. SimpleXML’s parser creates strange, unserializable, “built-in objects”.
Until you try to serialize them, you never realize they aren’t just strings. An explicit cast solves the problem.
// isn't serializable. $track->URI = $first_track->location; // resolves the problem! $track->URI = (string)$first_track->location;