PHP从SOAP返回对象

How to store SOAP returned value in PHP?

My PHP code using SOAP.

    <?php
        $client = new SoapClient("http://rscnagahrd/OracleWS/Oracle.asmx?WSDL");
        $result = $client->getFoods();
        echo $result;
    ?>

When I try to run the application I get the error:

Catchable fatal error: Object of class stdClass could not be converted to string in C:\apache\htdocs\food.php on line 4

I am doing this so that I could later parse the xml code:

$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($result);
$params = $dom->getElementsByTagName('FOOD_ID');
    foreach ($params as $param) {
    echo $param -> nodeValue, PHP_EOL;
}

The Soapclient object already has parsed the XML to a response structure (var_dump($result) and see). If you want to store it as a string, you'd have make it a string again somehow (serialize() if only PHP code needs to read it, json_encode() if you want to make it more language-agnostic are the usual suspects).

If you need to store the raw xml response, add array('trace' => true); as the 2nd parameter in SoapClient's constructor, and call $client->__getLastRequest();.

But, if you just want the answer used then & there the $result response is already parsed for you.