I have the following object array returned from a soap call:
$result = $this->soapClient->__soapCall($method, $arguments);
var_dump($result);
object(stdClass)#4 (1) {
["Jobs_GetResult"]=> object(stdClass)#5 (3) {
["Jobs"]=> array(4) {
[0]=> object(stdClass)#7 (19) {
["JobID"]=> int(55082846)
["JobName"]=> string(18) "Fix xyz"
}
}
["Errors"]=> object(stdClass)#10 (2) {
["Result"]=> int(0)
["Message"]=> string(0) ""
}
["RecordCount"]=> int(1)
}
}
I want to check if there are any errors - this is easy when the parent array key is known e.g:
if($result->Jobs_GetResult->Errors->Result > 0){
// display message
}
The issue is I do not know what the name of the top level array key is going to be for most of the calls as i'm using a generic method - in the above example it's Jobs_GetResult
so the above would work.
In instances where the top level array key is unknown how do I check if there are any errors returned?
In general the name of the parent array key is usually the name of the method call with Result
appended to it. so I was thinking doing something along the lines of:
if($result->$method . 'Result'->Errors->Result > 0){
// display message
}
But obviously the above syntax is incorrect. Any one know how to output value of $method
and chain it to $result
and append it with Result
Is there any other way I can check if the Errors array result is greater than 1 without knowing what the parent array key is?