I'm new to objects and classes but I'm trying to make a class for one of my simple soap requests so I can call up the status of a job with only the job number. I can't tell how to use the status result even though I can confirm it is working.
Here is what's in my class
public function validatejob() {
$client = new SoapClient('http://server/Service.asmx?wsdl');
$user = array("Username" => "", "Password" => "");
$jobnumber = $this->jobnumber;
$response1 = $client->GetSummaryJobStatus(
array(
"Credentials" => $user,
"JobNumber" => $jobnumber,
));
//$response1 -> GetSummaryJobStatusResult;
echo $response1 -> GetSummaryJobStatusResult;
}
Here is what's on my page:
$soap = new Soap; //create a new instance of the Users class
$soap->storeFormValues( $_POST );
$soap->validatejob();
print_r($soap->$response1->GetSummaryJobStatusResult);
This gets printed on the page:
HISTORY Fatal error: Cannot access empty property in /home/shawmutw/public_html/client/support.php on line 10
You can see that it fails, but HISTORY is the result I'm looking for. How do I properly echo the HISTORY part or store it on a variable to use?
You have to define a class property and assign the response to it like this:
class A {
public $response1;
public function validateJob() {
...
$this->response1 = $client->GetSummaryJobStatus(
...
}
}
Then you can access your class property through your instance like this:
print_r($soap->response1->GetSummaryJobStatusResult);
Your method "validateJob" does not return anything, and it does not store the result in any property, so there is no way to access it outside this method.
return $response1; // will help inside the method
$job = $soap->validateJob(); // save result
var_dump($job); // see what you get.