I have the following piece of code with which i am trying to populate a class from a resultSet. I find the common fieldNames in the resultSet and Class and dynamically build the set method for the class and try to set these values, but it dont seem to be working. Does anyone know if I can can call $thisClass->$setMethod, where $setMethod is built on the fly. below is my code. Any help would be greatly appreciated.
// Function to populate Class from ResultSet
function populateInfoObjectFromResultSet($resultSet,&$infoObject)
{
global $db;
// Getting all fieldNames
$fieldNames = array_keys ($resultSet->fields);
for ($a=0; $a<count($fieldNames); $a++)
{
$methodName = "set".ucfirst($fieldNames[$a]);
// if method exists, set it in the Info Object
if (method_exists($infoObject,$methodName))
{
$methodAppend = $methodName."(\"".$resultSet->fields[$fieldNames[$a]]."\")";
echo "Method $methodAppend Exists.<br>";
// trying to execute method on class
$infoObject->$methodAppend;
}
}
return $infoObject;
}
Thanks,
Nil
http://phpcodegenie.sourceforge.net/