Bug #71627 [Com]: save function doesn't work baddly
Edit report at https://bugs.php.net/bug.php?id=71627&edit=1
ID: 71627
Comment by: dubois-holvoet dot patrick at neuf dot fr
Reported by: dubois-holvoet dot patrick at neuf dot fr
Summary: save function doesn't work baddly
Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: Windows 10
PHP Version: 5.5.32
Block user comment: N
Private report: N
New Comment:
About the use of serialize / unserialize functions along with DOMDocument::save method I've
also found a good solution. Here it is.
--------------------------
For the serialize :
--------------------------
$data_serial = explode("\x00\x2A\x00", serialize($data)); //taking off 'NULL *
NULL' string added by the serialize function
$serialized_object = implode("\x5C\x30\x2A\x5C\x30", $data_serial); //and replace with the
'\0*\0' string
--------------------------
For the unserialize :
--------------------------
$data_serial = explode("\x5C\x30\x2A\x5C\x30",$obj_serial); //taking off the
'\0*\0' string
$serialized_object = implode("\x00\x2A\x00",$data_serial); //and replace with the
'NULL * NULL' string as previously added by the serialize operation
$object = unserialise($serialized_object);
Finally, I've written a note about these solutions onto the PHP documentation witch deal with
DOMDocument::save
Thanks to you
Previous Comments:
------------------------------------------------------------------------
[2016-02-24 14:00:19] ab@php.net
Thanks for the followup. Yeah, as alternative, you could also like base64 encode the data that you
put into XML, could work too.
Thanks.
------------------------------------------------------------------------
[2016-02-19 10:05:50] dubois-holvoet dot patrick at neuf dot fr
Finally I applied the addslashes() function before using my serialized object into the XML structure
generated with the DOMDocument class.
I do it like this :
addslashes(serialize($data));
And the result is perfect. The DOMDocument::save() runs fine now !
Of course when I want to use the serialized object I do it as follows :
unserialize(stripslashes($obj_serialized));
Thanks a lot for your feedback
------------------------------------------------------------------------
[2016-02-18 19:16:05] ab@php.net
Thanks for the report. Please post some reproduce code.
Cheers.
------------------------------------------------------------------------
[2016-02-18 19:11:10] dubois-holvoet dot patrick at neuf dot fr
Description:
------------
---
From manual page: http://www.php.net/domdocument.save
---
Here is the problem.
Before using DOMDocument to build a XML structure and save it in a file, I needed to serialize an
object witch has to be included in the XML structure.
But this object is from a class containing Protected members.
And as it's written in the PHP documentation the name of the protected members is prefixed by
the serialize function with an asterisc and a nul character on each side of the asterisc.
And these nul characters cause the bug with the DOMDocument::save function. The saved file is
troncated juste before the first nul character met.
Is there a solution to solve that ?
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71627&edit=1
Thread (5 messages)