RE: [PHP] visibility + unserialization

From: Date: Tue, 27 May 2008 05:30:14 +0000
Subject: RE: [PHP] visibility + unserialization
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-274715@lists.php.net to get a copy of this message
Can you please example code because I simulated the similar thing and it works fine here <?php class A { protected $x = '12345'; protected $y = '12345'; function __construct() { } public function Hello(){ echo Hello2; } } echo "<pre>"; $a = new A(); echo serialize($a); print_r($a); print_r(unserialize(serialize($a))); ?> O/P : O:1:"A":2:{s:4:"�*�x";s:5:"12345";s:4:"�*�y";s:5:"12345";}A Object ( [x:protected] => 12345 [y:protected] => 12345 ) A Object ( [x:protected] => 12345 [y:protected] => 12345 ) I think that’s perfectly fine. Chetan Dattaram Rane Software Engineer -----Original Message----- From: Ted Wood [mailto:ted-talks@codeoflife.ca] Sent: Monday, May 26, 2008 8:56 PM To: php-general@lists.php.net Subject: [PHP] visibility + unserialization I have a 4 year old framework that serializes objects and stores them in the database. It is now going PHP 5-only, so I began to add visibility to the class definitions of the serialized objects. However, then things didn't work properly after objects stored [before the visibility was added] were unserialized. For example, each protected field ended up creating two fields, with one followed by ":protected". Expected Result: ---------------------- object(Foo) { ["bar"]=> string(0) "banana" } Actual Result: ---------------------- object(Foo) { ["bar:protected"]=> string(0) "" ["bar"]=> string(6) "banana" } Anybody run into this, or can explain why this might be and how I can avoid it? Thanks, ~Ted -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#274715) next »