I have a php application that was developed with php4 and mySQL 4.1. The app currently runs fine on Windows server 2003, with php4 installed. However when I moved the app to another computer running php5 and mySQL 4.1, I started having issues with slow runs times and data in arrays being overwritten. Below is some specific code where a value in an array gets overwritten when a new value is added to the array.
1. // Getting ResultSet from Query
2. $resultSet = $thisDatabaseQuery->getRes
ultSet();
3. $thisDocumentsInfoArray = array();
4. $thisDocumentsInfo = new DocumentsInfo();
5. while (!$resultSet->EOF)
6. {
7. $this->populateDocumentsIn
foFromResu
ltSet($res
ultSet,$th
isDocument
sInfo);
8. $thisDocumentsInfoArray[] = $thisDocumentsInfo;
9. $resultSet->MoveNext();
10. } // end while
The code above reads in each record from the query (line 2.), formats the results into a local object ($thisDocumentsInfo - line 7.), and then adds that object to the array ($thisDocumentsInfoArray - line 8.). As subsequent records are read and formatted, as soon as the values are formatted into the local object (line 7.), all of the current objects stored in the array (line 8.) are changed to the current values. So what I get back is an array full of objects with the same values.
My thought is that when the object gets added to the array, it only stores a reference pointer to the original object since when the original object values change (line 7.), all the objects in the array change (line 8). I read on the php.net site that there were changes to the way arrays are handled with php5.
Any help would be greatly appreciated.
Start Free Trial