PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » XML » XML_Serializer » Bug #6127

Should serialize/unserialize private members

Details

Request #6127Should serialize/unserialize private members
Submitted2005-12-01 22:50 UTC
Frommichael at nolo dot com
StatusWont fix
PackageXML_Serializer
PHP Version5.1.0
OSAny
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>