Monday, 15 September 2014

PHP object serialization and unserialization not working properly -



PHP object serialization and unserialization not working properly -

i have 3 source files follows:

first 1 source_class.php

class macmini { public $memory = "16 gigabytes"; public $cpu = "intel core i7 @ 2.6ghz"; public $hd = "1tb @ 5200 rpms"; public function mem() { homecoming $this->memory; } public function centralpu() { homecoming $this->cpu; } public function hard_drive() { homecoming $this->hd; } }

///////////////////////////////////////////////////

second 1 serialize.php

include "source_class.php"; $mymini = new macmini; $mymini->cpu = "intel core i7 @ 3.4ghz"; $serialized = serialize($mymini); file_put_contents("store", $serialized);

//////////////////////////////////////////////

third 1 unserialize.php

include "source_class.php"; $data = file_get_contents("store"); $unserialized = unserialize($data); $mymini = new macmini; echo $mymini->cpu;

it produces next output: "intel core i7 @ 2.6ghz"

why, if property of cpu changed in serialize.php file, not reflected in unserialization? checked raw info contents of serialized file, "store" , cpu property reflected in serialized file when it's unserialized in unserialize.php property alter not reflected. why that? can explain?

the problem create new $mymini object , output cpu properity of newly created object. serialization/ unserialization doesn't create sense way.

change unserialize.php :

include "source_class.php"; $data = file_get_contents("store"); $mymini = unserialize($data); echo $mymini->cpu;

php serialization

No comments:

Post a Comment