Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.21.0

Bug #4575 _serializeObject and __sleep
Submitted: 2005-06-11 23:58 UTC
From: patxi at eslomas dot com Assigned: schst
Status: Closed Package: XML_Serializer
PHP Version: 4.3.10 OS: Linux
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 39 + 42 = ?

 
 [2005-06-11 23:58 UTC] patxi at eslomas dot com
Description: ------------ I think there is an error in the _serializeObject method of XML_serializer. If the object to be serialized has a __sleep method, it is called, but its return value is not captured. In fact, you get the attributes to be serialized always with get_object_vars function, however, when __sleep method exists, it must returns an array with the name of every attribute of the object to be serialized, so you shouldn't call get_object_vars in these cases. Reproduce code: --------------- The actual code is: ------------------- // check for magic function if (method_exists($object, '__sleep')) { $object->__sleep(); } $tmp = $this->options[XML_SERIALIZER_OPTION_LINEBREAKS]; $properties = get_object_vars($object); >>>>>>>>>>>> i think it should be: --------------------- // check for magic function if (method_exists($object, '__sleep')) { $properties = $object->__sleep(); } else $properties = get_object_vars($object); $tmp = $this->options[XML_SERIALIZER_OPTION_LINEBREAKS];

Comments

 [2005-09-06 19:15 UTC] schst
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.
 [2005-09-29 18:25 UTC] chris at ilikeu2 dot nl
This bug is fixed incorrectly. The __sleep() method returns an array of propertie _names_ and does not include the values. Also, I think it would be wise to call the __wakeup() afterwards. To come to the point, this is how I think the _serializeObject function should look: function _serializeObject(&$object, $tagName = null, $attributes = array()) { // check for magic function if (method_exists($object, '__sleep')) { $props = $object->__sleep(); $properties = array(); foreach($props as $prop) { $properties[$prop] = $object->$prop; } } else { $properties = get_object_vars($object); } if (method_exists($object, '__wakeup')) { $object->__wakeup(); } $tmp = $this->options[XML_SERIALIZER_OPTION_LINEBREAKS]; if (empty($tagName)) { $tagName = get_class($object); } // typehints activated? if ($this->options[XML_SERIALIZER_OPTION_TYPEHINTS] === true) { $attributes[$this->options[XML_SERIALIZER_OPTION_ATTRIBUTE_TYPE]] = 'object'; $attributes[$this->options[XML_SERIALIZER_OPTION_ATTRIBUTE_CLASS]] = get_class($object); } $string = $this->_serializeArray($properties, $tagName, $attributes); return $string; }
 [2005-09-29 19:15 UTC] schst
I'll change the __sleep() behaviour, but I will not call __wakeup() afterwards, as serialize() does not call __wakeup().
 [2005-09-30 13:41 UTC] schst
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.