ID: 30321
User updated by: matthias dot hoseit at comline dot de
Reported By: matthias dot hoseit at comline dot de
-Status: Bogus
+Status: Open
Bug Type: DOM XML related
Operating System: Windows 2000, Apache 1.3.31
PHP Version: 5.0.2
New Comment:
Thank you for your quick answer.
Sorry but I disagree. In my opinion this is a bug.
If you serialize an object (in this case a DOMDocument object which is
a built-in class since PHP5 and not an external class like the domxml
extension in PHP4) you get a string containing a byte-stream
representation of a value (including the properties and methods since
PHP4).
But in this case, after serialising the DOMDocument object you get a
byte-stream representation without any properties. It is empty:
"O:11:"DOMDocument":0:{}".
According to the description of serialize() in the PHP Manual,
serialize() handles all types, except the resource-type. Since the PHP
function is_resource() returns false, the DOMDocument object is not a
resource and therefore should be serialized correctly.
Previous Comments:
------------------------------------------------------------------------
[2004-10-04 15:47:41] [EMAIL PROTECTED]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
.
------------------------------------------------------------------------
[2004-10-04 15:32:05] matthias dot hoseit at comline dot de
Description:
------------
The function serialize() doesn't work with a DOMDocument object. After
you've serialized and unserialized an object of DOMDocument the
unserialized object seems to be empty (The object knows that it is a
DOMDocument Object, but all data is lost).
Reproduce code:
---------------
<?PHP
//----------------------------------------------Building a working
DOMDocument-----------------------------------
//create new DOMDocument
$domDoc1 = new DOMDocument();
//create some elements
$rootElement = $domDoc1->createElement("Element1");
$element2 = $domDoc1->createElement("Element2", "Value2");
//adding element to root
$rootElement->appendChild($element2);
//adding root to DOM
$domDoc1->appendChild($rootElement);
//show that DOMDocument is working right now
$elements1 = $domDoc1->getElementsByTagName("Element2");
foreach ($elements1 as $val) {
echo "TagName = '".$val->tagName."' ";
echo "Value = '".$val->nodeValue."'<br>";
}
//----------------------------------------------now the strange
behavior-----------------------------------------
//now serialize DOMObject
$serialize1 = serialize($domDoc1);
//The serialized DOMObject seems to be empty
echo $serialize1."<br>";
//unserialize
$unserialize1 = unserialize($serialize1);
//----------------------------------------------the
error--------------------------------------------------------
//And now there is the error.. $unserialize1 seems to be no
DOMDocument or an empty one
$elements2 = $unserialize1->getElementsByTagName("Element2");
//You get the error message: Warning: Couldn't fetch DOMDocument in
....
//print_r shows an empty object
print_r($unserialize1);
?>
Expected result:
----------------
I thought, when you unserialize a DOMDocument object you get a
DOMDocument object with all data of the original one (NodeLists etc).
Actual result:
--------------
After unserializing a serialized DOMDocument object you get an empty
DOMDocument object.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30321&edit=1