title: Wsdl return php object
body: <p><strong>Edit</strong>: There was no problem with my code. Server was reading wsdl file from cache. To solve the issue:</p>
  
  <ol>
  <li>Disable the cache with <code>ini_set("soap.wsdl_cache_enabled", 0);</code></li>
  <li>Otherwise delete cache file from /tmp directory each time after changing wsdl file.</li>
  </ol>
  
  <p>I am using zend soap for creating a web service. I am trying to return a complex type from it. My php class looks like this: </p>
  
  <pre><code>require_once 'myclass.php';
  
  class MyService {
      /**
       *
       * @param integer param1
       * @param string param2
       * @return myclass
       */
      public function myfunction ($param1, $param2) {
  
          $myobj= new myclass();
          $myobj-&gt;returncode = 100;
          return $myobj;
      }
  }
  </code></pre>
  
  <p>myclass is a simple class with two public variables</p>
  
  <pre><code>class myclass {
      /** @var int */
      public $returncode = '0';
  
      /** @var string */
      public $returnmessage = 'Başarılı';
  
  }
  </code></pre>
  
  <p>I am using <a href="http://framework.zend.com/manual/en/zend.soap.autodiscovery.html" rel="nofollow">AutoDiscovery</a> for generating wsdl file:</p>
  
  <pre><code>&lt;definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://my.domain.com/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="MyService" targetNamespace="http://my.domain.com/wsdl/"&gt;
    &lt;types&gt;
    &lt;xsd:schema targetNamespace="http://my.domain.com/wsdl/"&gt;
    &lt;xsd:complexType name="myclass"&gt;
      &lt;xsd:all&gt;
      &lt;xsd:element name="returncode" type="xsd:int"/&gt;
      &lt;xsd:element name="returnmessage" type="xsd:string"/&gt;
      &lt;/xsd:all&gt;
    &lt;/xsd:complexType&gt;
    &lt;/xsd:schema&gt;
    &lt;/types&gt;
    &lt;portType name="MyServicePort"&gt;
    &lt;operation name="myfunction"&gt;
    &lt;documentation&gt;&lt;/documentation&gt;
    &lt;input message="tns:myfunctionIn"/&gt;
    &lt;output message="tns:myfunctionOut"/&gt;
    &lt;/operation&gt;
    &lt;/portType&gt;
    &lt;binding name="MyServiceBinding" type="tns:MyServicePort"&gt;
    &lt;soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
    &lt;operation name="myfunction"&gt;
    &lt;soap:operation soapAction="http://my.domain.com/wsdl/#myfunction"/&gt;
    &lt;input&gt;
    &lt;soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://my.domain.com/wsdl/"/&gt;
    &lt;/input&gt;
    &lt;output&gt;
    &lt;soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://my.domain.com/wsdl/"/&gt;
    &lt;/output&gt;
    &lt;/operation&gt;
    &lt;/binding&gt;
    &lt;service name="MyServiceService"&gt;
    &lt;port name="MyServicePort" binding="tns:MyServiceBinding"&gt;
    &lt;soap:address location="http://my.domain.com/wsdl/"/&gt;
    &lt;/port&gt;
    &lt;/service&gt;
    &lt;message name="myfunctionIn"&gt;
    &lt;part name="param1" type="xsd:int"/&gt;
    &lt;part name="param2" type="xsd:string"/&gt;
  
    &lt;/message&gt;
      &lt;message name="myfunctionOut"&gt;
      &lt;part name="return" type="tns:myclass"/&gt;
    &lt;/message&gt;
    &lt;/definitions&gt;
  </code></pre>
  
  <p>I can receive primitive types without a problem. When i try to return an object it converts object to string (Displays "Object") and returns:</p>
  
  <pre><code>&lt;SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.domain.com/wsdl" 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/"&gt;
  &lt;SOAP-ENV:Body&gt;
     &lt;ns1:myfunctionResponse&gt;
        &lt;return xsi:type="xsd:string"&gt;Object&lt;/return&gt;
    &lt;/ns1:myfunctionResponse&gt;
  &lt;/SOAP-ENV:Body&gt;
  </code></pre>
  
  <p> </p>
  
  <p>I want a result like this:</p>
  
  <pre><code>&lt;myclass&gt;
    &lt;returncode&gt;100&lt;/returncode&gt;
    &lt;returnmessage&gt;Ok&lt;/returnmessage&gt;
  &lt;/myclass&gt;
  </code></pre>
  
  <p>Thank you.</p>