Hi,
I have a class that is query data via a SOAP client. the results of the query are returned as an array of objects. Something strange is happening. I'm not sure if it only occurs when there is one element in the array.
Here is the code:
function getNotes($ticketid){
$ticketid = $this->ms_escape_string($ticketid);
$conn = new Connections();
$client = $conn->connectToAPI();
$xml = array('sXML' =>"<queryxml>".
"<entity>TimeEntry</entity>".
"<query>".
"<field>TicketID".
"<expression op='equals'>$ticketid</expression>".
"</field>".
"</query>".
"</queryxml>");
$result = $client->query($xml);
$noteso = $result->queryResult->EntityResults->Entity;
//set array counter
$x=0;
var_dump($noteso);
foreach($noteso as $note){
var_dump($note->ResourceID);
$name = $this->getResourceName($note->ResourceID);
$timeentryarray[$x] = array('createdate' => $note->CreateDateTime,
'summarynotes' => $note->SummaryNotes,
'resource' => $name
);
$x++;
}
return $timeentryarray;
}
when the application run the var_dump($noteso) is fine. Prints out
object(stdClass)#12 (15) {
["id"]=> int(36988)
["UserDefinedFields"]=> object(stdClass)#13 (0) { }
["TicketID"]=> int(26390)
["InternalAllocationCodeID"]=> int(28303142)
["Date"]=> string(19) "2010-10-25T00:00:00"
["StartDateTime"]=> string(19) "2010-10-25T04:59:00"
["EndDateTime"]=> string(19) "2010-10-25T05:04:00"
["HoursWorked"]=> float(0.08)
["HoursToBill"]=> float(0.0833333358)
["OffsetHours"]=> float(0)
["SummaryNotes"]=> string(69) "Hi Sarah, Do you have an example of a bounced email? Regards Simon"
["InternalNotes"]=> string(0) ""
["RoleID"]=> int(24482927)
["CreateDateTime"]=> string(23) "2010-10-25T05:06:28.023"
["ResourceID"]=> int(29699970)
}
but the second var_dump($note->ResourceID) in the foreach loop only shows
NULL
then each line that accesses the array after that throws an error:
Notice: Trying to get property of non-object in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\ClientPortal\classes\OpenTickets.php on line 204
Line 204 being
$name = $this->getResourceName($note->ResourceID);
Been trying to debug this one for a while, can someone offer any suggestions?
Regards,
Jonesy