php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71627 save function doesn't work baddly
Submitted: 2016-02-18 19:11 UTC Modified: 2016-02-24 14:00 UTC
From: dubois-holvoet dot patrick at neuf dot fr Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.5.32 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dubois-holvoet dot patrick at neuf dot fr
New email:
PHP Version: OS:

 

 [2016-02-18 19:11 UTC] 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 ?      


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-18 19:16 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2016-02-18 19:16 UTC] ab@php.net
Thanks for the report. Please post some reproduce code.

Cheers.
 [2016-02-19 10:05 UTC] 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-24 14:00 UTC] ab@php.net
-Status: Feedback +Status: Not a bug
 [2016-02-24 14:00 UTC] 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-25 20:37 UTC] dubois-holvoet dot patrick at neuf dot fr
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 11:01:33 2024 UTC