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  


 [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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2005-09-30 13:41 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!