2013-06-30 08:53



How to store SOAP returned value in PHP?

My PHP code using SOAP.

        $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;
$params = $dom->getElementsByTagName('FOOD_ID');
    foreach ($params as $param) {
    echo $param -> nodeValue, PHP_EOL;
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanhui1869 duanhui1869 8年前

    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.

    点赞 评论 复制链接分享