相关文章推荐
大力的电梯  ·  database - How do you ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

However, every combination of soapvar and soapparam I've been able to think up either makes it impossible for me to duplicate the nested 'names' tag. I can get 1 sub tag like so:

$flexFields = array(
  'names'=> new SoapVar(
      new SoapVar(array('names'=>'IAG Group'),SOAP_ENC_OBJECT),
    SOAP_ENC_OBJECT)

This generates:

<flexFields xsi:type="ns2:SoapNamedValues">
  <names xsi:type="names">
    <names xsi:type="xsd:string">IAG Group</names>
  </names>
</flexFields>

But any attempt I make to get the names tag to repeat either generates a dreaded BOGUS element if I use SOAP_ENC_OBJECT, or wraps every item in another 'item' element if I use SOAP_ENC_ARRAY, which is also not desirable.

I know I could just manually create what I want and load it with XSD_ANYXML, but that is getting close to the line of defeating the purpose of using the SOAP library.

Can anyone provide an example of just how to perfectly balance the soapvar/soapparam + array nesting to get this to actually work? Or am I attempting the impossible with PHP's SOAP library?

$Names=array();
$Names[]=new SoapVar("IAG Group",XSD_STRING,null,null,'names');
$Names[]=new SoapVar("Ticket #",XSD_STRING,null,null,'names');
$BigNames=new SoapVar($Names,SOAP_ENC_OBJECT,null,null,'Names');

This creates and array of of SoapVar objects ($Names) and places them in the BigNames object, creating an output like this:

<Names>
    <names>IAG Group</names>
    <names>Ticket #</names>  
</Names>

You can then create another SoapVar object for FlexFields, but for some reason you can't place a SoapVar object directly into another, it has to be stored in an array...

I want to do this:

$FlexFields=new SoapVar($BigNames,SOAP_ENC_OBJECT,null,null,'FlexFields');

This works:

$FF=array($BigNames);
$FlexFields=new SoapVar($FF,SOAP_ENC_OBJECT,null,null,'FlexFields');

I ran into the BOGUS tag problem also. My solution involved using an ArrayObject in place of array primitives. The objects are all then converted to SoapVar objects. It seems the soap library really wants to deal with objects everywhere. I have a more complete writeup here:

http://www.fischco.org/blog/2011/3/26/php-soapserver-objects-arrays-and-encoding.html

Nice writeup. I ended up doing something similar in the end, creating stdClass() generics and wrapping those, but I like the arrayobject too. Had no idea that sucker existed. But yeah, had to go objects all the way. Arrays choked it. – mainegreen Apr 11, 2011 at 12:40

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.