我是对象和类的新手,但我正在尝试为我的一个简单的soap请求创建一个类,这样我就可以调用只有作业号的作业状态。我无法告诉如何使用状态结果,即使我可以确认它是否正常工作。
这是我班上的内容
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;
}
以下是我页面上的内容:
$soap = new Soap; //create a new instance of the Users class
$soap->storeFormValues( $_POST );
$soap->validatejob();
print_r($soap->$response1->GetSummaryJobStatusResult);
这会打印在页面上:
HISTORY Fatal error: Cannot access empty property in /home/shawmutw/public_html/client/support.php on line 10
你可以看到它失败了,但是HISTORY是我正在寻找的结果。如何正确回显HISTORY部分或将其存储在要使用的变量上?
答案 0 :(得分:1)
您必须定义一个类属性并将响应分配给它:
class A {
public $response1;
public function validateJob() {
...
$this->response1 = $client->GetSummaryJobStatus(
...
}
}
然后您可以通过您的实例访问您的类属性,如下所示:
print_r($soap->response1->GetSummaryJobStatusResult);
答案 1 :(得分:1)
您的方法“validateJob”不返回任何内容,并且它不会将结果存储在任何属性中,因此无法在此方法之外访问它。
return $response1; // will help inside the method
$job = $soap->validateJob(); // save result
var_dump($job); // see what you get.