2

I'm running a PHP SoapServer. This is a example of a request I can get in my request body:

<MyFunctionRequest>
    <Item>
        <Param Attr="XX">Value</Param>
    </Item>
</MyFunctionRequest>

The problem is, I can't seem to be able to read the attribute Attr in my SoapServer function. If I print the parameters I get in my SoapServer function, I get this:

StdClass Object
(
    [Item] => stdClass Object
    (
        [Param] => Value
    )
)

My SoapServer is built like this:

<?php
class MySoapServer {
    public function index() {
        $server = new SoapServer($pathToWsdl);
        $server->addFunction(array('MyFunction'));
    }
}

function MyFunction($params) {
    log(print_r($params, true));
    // function code, need the attribute Attr somewhere in here
}

So how can I get the attribute Attr in my function code? Thanks.

user1026090
  • 458
  • 3
  • 9
  • 23

1 Answers1

0

https://stackoverflow.com/a/66821464/372215

I just had this issue and found this solution...

Php Soap Server (under the hood) does not parse out the attributes.

parse data with DOMDocument to get all attributes

$dom = new \DOMDocument;
$dom->loadXML(file_get_contents("php://input"));

convert to array for easy use...

What is the best php DOM 2 Array function?

results

  "MyFunctionRequest" => array:1 [
    "Item" => array:1 [
      "Param" => array:2 [
        "@attributes" => array:1 [
          "Attr" => "XX"
        ]
        "_value" => "Value"
      ]
    ]
  ]
Artistan
  • 1,982
  • 22
  • 33