#31869 [Asn]: Returned SOAP-structs are mapped to stdclass instead of matching user class.

From: Date: Thu, 10 Feb 2005 11:52:37 +0000
Subject: #31869 [Asn]: Returned SOAP-structs are mapped to stdclass instead of matching user class.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-73744@lists.php.net to get a copy of this message
ID: 31869 Updated by: dmitry@php.net Reported By: wolfgang dot glas at ev-i dot at Status: Assigned Bug Type: SOAP related Operating System: any PHP Version: 5.0.3 Assigned To: dmitry New Comment: You can do this with "classmap" option in SoapClient/SoapServer constructor. $client = new SoapClient(("http://localhost:8080/axis/base?wsdl", array("classmap"=>array("SOAPStruct"=>"SOAPStruct"))); Previous Comments: ------------------------------------------------------------------------ [2005-02-07 10:17:12] wolfgang dot glas at ev-i dot at Description: ------------ The code fragment below shows a PHP SOAP client calling the echoStruct() function from the 'base' example of AXIS C++ (Apcahe's C++ SOAP-server). This example is supposedly included in most SOAP servers. If not, contact me for more information. The struct SOAPStruct is defined in the according wsdl-file an the struct correctly passed over to the SOAP server. When an object of type SOAPStruct is returned by the SOAPClient, the returned object is of type 'stdclass' with the appropriate attributes. The returned object can be easily mappedd back to the user-defined class, as shown below in the fromStdClass() member function. Nevertheless, it would feasible for most users, if the SOAPClient mapped the returned value directly to an Object of type 'class SOAPStruct' in the case that the user defined a class with a name that matches the struct name in the wsdl-file. IMHO, this feature should become part of the PHP-5.1 development schedule. TIA for considering this suggestion, Wolfgang Reproduce code: --------------- class SOAPStruct { public $varString; public $varInt; public $varFloat; function __construct($s= "",$i = 0,$f = 0.0) { $this->varString=$s; $this->varInt=$i; $this->varFloat=$f; } function fromStdClass($v) { foreach($v as $key => $value) { $this->$key= $value; } } function printMe() { echo "string=".$this->varString."\nint=".$this->varInt."\nfloat=".$this->varFloat."\n"; } } $s=new SOAPStruct("s_string",43,3.1415926535); $r=new SOAPStruct; $client = new SoapClient("http://localhost:8080/axis/base?wsdl"); echo "********* echoStruct:\n"; echo "**** s:\n"; $s->printMe(); $r->fromStdClass($client->echoStruct($s)); echo "**** r:\n"; $r->printMe(); ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31869&edit=1

« previous php.bugs (#73744) next »