title: PHP NuSoap Server return array of complex types
body: <p>There are many questions relating to this online which are just unanswered and I am looking for a solution all over the place.
  So I have a Soap Server with NuSoap and I am trying to return an array of database rows (modelled here as a hardcoded list of PS4 game entities).</p>
  
  <p>The code below here works (with slight modification) for returning a single array, however I am unable to get more than 1 of them to be returned.</p>
  
  <p>Does anyone have a solution for this as I have spent the day trying various solutions from online as well as the code below:</p>
  
  <pre><code>//Settings
  
  $ns = 'http://'.$_SERVER['HTTP_HOST'].'/index.php/soapserver/';
  $this-&gt;load-&gt;library("Nusoap_library");
  $this-&gt;nusoap_server = new soap_server();
  $this-&gt;nusoap_server-&gt;configureWSDL("Nusoap Server", $ns);
  $this-&gt;nusoap_server-&gt;wsdl-&gt;schemaTargetNamespace = $ns;
  
  //Complex Types and Function registers on server
  
  // Complex Type "Game":
  $this-&gt;nusoap_server-&gt;wsdl-&gt;addComplexType(
      'Game', // the type's name
      'complexType',
      'struct',
      'all',
      '',
      array(
          'title' =&gt; array('name'=&gt;'title','type'=&gt;'xsd:string'),
          'description' =&gt; array('name'=&gt;'description','type'=&gt;'xsd:string'),
          'price' =&gt; array('name'=&gt;'price','type'=&gt;'xsd:string'),
      )
  );
  
  
  // Complex Type "Games" (array of Game):
  $this-&gt;nusoap_server-&gt;wsdl-&gt;addComplexType(
      'Games',
      'complexType',
  'array',
  '',
  'SOAP-ENC:Array',
  array(),
  array(
      array(
          'ref'=&gt;'SOAP-ENC:arrayType',
          'wsdl:arrayType'=&gt;'tns:Game[]'
      )
  ),
  'tns:Game'
  );
  
  // Get_Games
  $this-&gt;nusoap_server-&gt;register(
      'get_games',
      array('instance_id' =&gt; 'xsd:string'),
      array('return'=&gt;'tns:Games'),
      '',
      false,
      'rpc',
      'encoded',
      'Return array of Games'
  );
  
  // [REGISTERED METHODS]:
  function get_games($instance_id)
  {
      // [Hardcoded Games list]:
      $games = array(
          array(
              'title' =&gt; 'Killzone: Shadow Fall',
              'description' =&gt; 'test desc ',
              'price' =&gt; '49.99'
          ),
          array(
              'title' =&gt; 'Battlefield',
              'description' =&gt; 'blah blah',
              'price' =&gt; '54.99'
          )
      );
  
      return $games;
  }
  </code></pre>
  
  <p>QUESTION:</p>
  
  <p>What changes do I need to make to the above code to get this server to return an array of game entities.</p>
  
  <p>It works fine if I return $games[0] with some minor changes to the code, however I can not seem to get the above code to work.</p>
  
  <p>Any help or advice appreciated...</p>
  
  <p>EDIT:</p>
  
  <p>I consistantly get the following error:</p>
  
  <pre><code>    Error
  
      XML error parsing SOAP payload on line 10: Invalid document end
  
      Response
  
      HTTP/1.1 200 OK
      Date: Sun, 16 Mar 2014 20:35:35 GMT
      Server: Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.6
      X-Powered-By: PHP/5.5.6
      X-SOAP-Server: NuSOAP/0.9.5 (1.123)
      Content-Length: 1688
      Content-Type: text/xml; charset=ISO-8859-1
  
       &lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"&gt;
  
      &lt;h4&gt;A PHP Error was encountered&lt;/h4&gt;
  
      &lt;p&gt;Severity: Notice&lt;/p&gt;
      &lt;p&gt;Message:  Array to string conversion&lt;/p&gt;
      &lt;p&gt;Filename: lib/nusoap.php&lt;/p&gt;
      &lt;p&gt;Line Number: 6132&lt;/p&gt;
  
      &lt;/div&gt;&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"&gt;
  
      &lt;h4&gt;A PHP Error was encountered&lt;/h4&gt;
  
      &lt;p&gt;Severity: Notice&lt;/p&gt;
      &lt;p&gt;Message:  Array to string conversion&lt;/p&gt;
      &lt;p&gt;Filename: lib/nusoap.php&lt;/p&gt;
      &lt;p&gt;Line Number: 6132&lt;/p&gt;
  
      &lt;/div&gt;&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;&lt;SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://localhost/index.php/soapserver/"&gt;&lt;SOAP-ENV:Body&gt;&lt;ns1:get_gamesResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:Game[2]"&gt;&lt;item xsi:type="tns:Game"&gt;&lt;title xsi:type="xsd:string"&gt;Killzone: Shadow Fall&lt;/title&gt;&lt;description xsi:type="xsd:string"&gt;test desc&lt;/description&gt;&lt;price xsi:type="xsd:string"&gt;49.99&lt;/price&gt;&lt;/item&gt;&lt;item xsi:type="tns:Game"&gt;&lt;title xsi:type="xsd:string"&gt;Battlefield&lt;/title&gt;&lt;description xsi:type="xsd:string"&gt;blah blah&lt;/description&gt;&lt;price xsi:type="xsd:string"&gt;54.99&lt;/price&gt;&lt;/item&gt;&lt;/return&gt;&lt;/ns1:get_gamesResponse&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;
  </code></pre>