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

Bug #4575 _serializeObject and __sleep
Submitted: 2005-06-11 18:58 UTC Modified: 2005-09-30 08:41 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  


 [2005-06-11 18: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 14: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 13: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 14: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 08: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.