Is there a way to return in soap an object with his methods? If i return xsd:struct in WSDL i only get the properties of the object but i can’t use any of the methods.
For example
class person
{
var $name = "My name";
public function getName()
{
return $this->name;
}
}
So after fetching the object:
$client = new SoapClient();
$person = $client->getPerson();
echo $person->getName(); // Return "My Name";
Thanks.
You cannot do this with
SOAP. Basically your PHP class is being mapped to an XML data structure that’s defined by an XML schema. This mapping only includes properties and cannot include executable code.SOAPis designed for interoperability and naturally you cannot share code between, let’s say, PHP and Java or .NET. On the receiving side your XML data structure is being transformed into a data structure of the client’s programming language (a PHP class if you useSoapClientor aC#class if you useC#). As the XML data structure only carries property information the executable part of the originating class cannot be rebuilt.But there is one thing that can help if both the SOAP server and the connecting client have access to the same code base (which means the same classes). You can define a mapping between a
XMLtype and aPHPclass in theSoapClient‘s constructor using theclassmap-option. This allowsSoapClientto map incoming XML data structures to real PHP classes – given the fact that both the server and the client have access to the relevant class definition. This allows you to use methods on the receiving side of theSOAPcommunication.The
WSDLmight look like (copied from one of theSoapClienttests and adpated):The State of SOAP in PHP might be interesting if you’re doing
SOAPin PHP.