Storing objects in PHP with serialize
2006-10-25 02:50:27
Serialization is the process of converting some object into an easy to manage string, maintaining the ability of inverting the process and obtaining the object back from the string.
So, we could convert database rows into text lines in order to save the changes in a text file, save our program's objects when it ends and recover them at the next run, or create object persistence systems like caches.
With PHP is really easy, because we have the runtime function serialize:
<?
$vector["hola"]="Epa{}";
$vector["electric"]="Head";
print_r($vector);
$temporal=serialize($vector);
echo $temporal."\n";
$matrix=unserialize($temporal);
print_r($matrix);
?>
Output:
Array
(
[hola] => Epa{}
[electric] => Head
)
a:2:{s:4:"hola";s:5:"Epa{}";s:8:"electric";s:4:"Head";}
Array
(
[hola] => Epa{}
[electric] => Head
)
Rollos antiguos
2006-10-25 02:49:52 - Guardar objetos en PHP con serialize.
2006-10-25 02:48:32 - Mejor musica que publicidad.
2006-10-25 02:46:04 - Abrir programas asociados desde la linea de comandos.
2006-10-25 02:41:10 - Cambiar la licencia de Windows XP.
2006-10-25 02:07:27 - Volcados de impresora, guardando impresiones.