I have 17 rows in a table -- there is a primary key logID that means no row should ever be exactly the same. I have a class I'm working on to do by db dirty work -- so I use it to pull all rows that have 'type' of 'err', for example, which equates to 8 rows. Then I pull new rows (with a column=value that ALL match, so it should be 17 rows) and my object is supposed to compare them against the previous rows and only enter in those that differ. Here's the code:
if (isset($this->rows)) {
// Find only the row objects in the results that differ from those already loaded
$newTempRows = array_udiff($tempRows, $this->rows, array(get_class($this), '_filterObjDuplicates'));
// And now merge the new row objs with the already loaded rows
$this->rows = array_merge($this->rows, $newTempRows);
}
else {
$this->rows = $tempRows;
}
And here's _filterObjDuplicates:
protected static function _filterObjDuplicates($targetObj, $sourceObj) {
// Comparison function -- returns the casted integer of the boolean
// returned for $a != $b (if different, return 1; if same, return 0)
return (int)!(serialize($targetObj) == serialize($sourceObj));
}
For reference, $this->rows is an array of all row objects loaded. $tempRows are the rows I just received on the current call. $newTempRows should be only the rows different between the first two.
So, when I var_dump $this->rows after each pull of the database - I should get 8 rows, and then 17. Instead, I get 8 and then 25 (meaning it saw no equal rows and simply added all 17 to the existing 8). I've echoed and var_dumped just about everything I can to make sure the code continues along as planned, it only hiccups during the comparison. Can you see where my code goes wrong?
(NOTE: I serialize for comparison because of erratic PHP obj comparison behavior)