ZF-6785: Inconsistencies in Zend_Db_Table_Row_Abstract::toArray() and ::setFromArray()
Description
The data returned by the toArray() function does not use getter methods that may have been set up, but setFromArray() does use the setter methods. As a result, while the following code can be perfectly valid for copying a property from one row object to another:
$rowObj1->prop1 = $rowObj2->prop1
This code can fail:
$rowObj1->setFromArray($rowObj2->toArray());
Specific example - Suppose prop1 is serialized before being written to the database, and the model contains the following functions:
public function setProp1($value) {
$this->set('prop1', serialize($value));
}
public function getProp1() {
return unserialize($this->get('prop1'));
}
On $rowObj1, the property prop1 would be serialized twice after running $rowObj1->setFromArray($rowObj2->toArray()).
I suspect the correct solution is to have toArray() use any getter methods that may have been set up.
Comments
Posted by Mason Wolf (dooby) on 2009-05-22T18:44:03.000+0000
added code-block tags to improve readability
Posted by Rob Allen (rob) on 2012-11-20T20:52:55.000+0000
Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".
Feel free to re-open and provide a patch if you want to fix this issue.