不知道如何从我的对象中返回一个简单的字符串


Can't figure out how to echo a simple string from my object

我是对象和类的新手,但我正试图为我的一个简单的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部分或将其存储在变量中以供使用?

你必须定义一个class属性,并像这样为它分配响应:

class A {
    public $response1;
    public function validateJob() {
        ...
        $this->response1 = $client->GetSummaryJobStatus(
        ...
    }   
}

然后你可以通过实例访问你的类属性,像这样:

print_r($soap->response1->GetSummaryJobStatusResult);

您的方法"validateJob"不返回任何内容,也不将结果存储在任何属性中,因此无法在该方法之外访问它。

return $response1; // will help inside the method
$job = $soap->validateJob(); // save result
var_dump($job); // see what you get.