Home » XML » XML_Serializer » Bug #6127
Should serialize/unserialize private members
Details
| Request #6127 | Should serialize/unserialize private members |
|---|---|
| Submitted | 2005-12-01 22:50 UTC |
| From | michael at nolo dot com |
| Status | Wont fix |
| Package | XML_Serializer |
| PHP Version | 5.1.0 |
| OS | Any |
| Roadmaps | (Not assigned) |
Comments
[2005-12-01 22:50 UTC] michael at nolo dot com
Description:
------------
A major difference between XML_Serializer/XML_Unserializer and PHP's built-in serialize() and unserialize() methods is that the latter methods allow an object to be completely serialized, including private members. The former simply ignores private members.
If this package is intended to serve as an XML-ized replacement for PHP's built-in serialization, this seems like a glaring omission.
I do realize this may not be easiest thing to accomplish! If there's a workaround, I'd love to know about it.
See the attached test code.
Test script:
---------------
require_once("XML/Serializer.php");
class Foo {
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public $a;
private $b;
};
$f = new Foo("foo", "bar");
$s = new XML_Serializer();
$serializer_options = array ('typeHints' => true);
$serializer = &new XML_Serializer($serializer_options);
$status = $serializer->serialize($f);
header('Content-type: text/xml');
echo $serializer->getSerializedData();
Expected result:
----------------
<Foo _class="Foo" _type="object">
<a _type="string">foo</a>
<b _type="string">bar</b>
</Foo>
Actual result:
--------------
<Foo _class="Foo" _type="object">
<a _type="string">foo</a>
</Foo>