Working with serialized MidgardObjects
2005-04-25 11:55

I have today run a few small tests regarding the serialization of Midgard Objects. To the contrary of my expectations, it works like a breeze. Which is good for the NAP cache I'm planning to write, which will include Midgard Objects in a serialized form (for quick Metadata access).

If you want to verify it in your Midgard Installation (my test was on a 1.6 series system), here is the test code I used:

<pre>
<?php
$topic = mgd_get_topic(30);

echo "Topic #30 as in DB:\n";
print_r($topic);

echo "\n\n";

$serialized_topic = serialize($topic);
echo "Serialized Topic (line-wrapped):\n";
echo wordwrap($serialized_topic, 80, "\n", 1) . "\n";
echo "Serialized Topic:\n{$serialized_topic}\n";

echo "\n\n";

/*
$serialized_topic = '...';
*/

$new_topic = unserialize($serialized_topic);
echo "Unserialized Topic:\n";
print_r($new_topic);

echo "\n\n";

$new_topic->code = "blah2";
$result = $new_topic->update();
echo "Tried to update the topic, result was {$result}, last midgard error: " . mgd_errstr();
$new_topic->parameter("test","test","test");

$topic = mgd_get_topic(30);

echo "Topic #30 as in DB:\n";
print_r($topic);


?>
</pre>