php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42184 Object Type mismatch using classmap in WSDL mode
Submitted: 2007-08-02 17:27 UTC Modified: 2007-08-22 14:46 UTC
From: heitor dot m at gmail dot com Assigned: dmitry (profile)
Status: Not a bug Package: SOAP related
PHP Version: 5.2.3 OS: Linux RedHat Enterprise V4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: heitor dot m at gmail dot com
New email:
PHP Version: OS:

 

 [2007-08-02 17:27 UTC] heitor dot m at gmail dot com
Description:
------------
tryning to get the object type that i was specified in classmap option. i ever get a object of the type stdClass.

I'm expecting to get in this case a instance of the Class PHPObject previusly declared by me.

I already search for related bug reports and just has found this:
http://bugs.php.net/bug.php?id=42157
thats already closed.

Reproduce code:
---------------
SERVER(teste_ser.php):
<?php

ini_set("soap.wsdl_cache_enabled", "0"); 

class PHPObject
{
	public $prop1;
	public $prop2;
	public $propc;

	public function __construct($a, $b, $c)
	{
		$this->prop1 = $a;
		$this->prop2 = $b;
		$this->propc = $c;
	}
}

function send($arg_obj)
{
	$obj = new PHPObject("SERVER_1", "SERVER_2", "SERVER_3");
	return $obj;
}

$classmap = array('WSDLObject' => 'PHPObject');

$server = new SoapServer("teste.wsdl", array('classmap' => $classmap));

$server->addFunction(array("send"));

$server->handle();

?>
=============================================
CLIENT(teste_cli.php):
<?php

ini_set("soap.wsdl_cache_enabled", "0"); 

class PHPObject
{
	public $prop1;
	public $prop2;
	public $propc;

	public function __construct($a, $b, $c)
	{
		$this->prop1 = $a;
		$this->prop2 = $b;
		$this->propc = $c;
	}
}

try {
	
	$classmap = array('WSDLObject' => 'PHPObject');
	
	$client = new SoapClient("teste.wsdl", array("classmap"  => $classmap, 'trace' => 1));

	$arg_obj = new PHPObject("ARG_1", "ARG_2", "ARG_3");
    
	$res = $client->send($arg_obj);
	
	echo "<hr>RESPONSE FROM SERVER<hr><pre>";
	var_dump($res);
	echo "</pre><hr>";

	echo "<hr>SOAP RESPONSE<hr><pre>";
	echo htmlspecialchars(str_replace("><", ">\n<", $client->__getLastResponse()));
	echo "</pre><hr>";
	
} catch (SoapFault $sf) {
	
	echo "<hr><pre>";
	print_r("(" . $sf->faultcode . ") " . $sf->faultstring);
	echo "</pre><hr>";
	
} catch (Exception  $e) { 
	
	echo "<hr><pre>";
	print_r($e);
	echo "</pre><hr>";

} 

?>
======================================================
WSDL(teste.wsdl):
<?xml version="1.0"  encoding="UTF-8"?>

<definitions
	xmlns="http://schemas.xmlsoap.org/wsdl/" 
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
	xmlns:tns="http://www.sit.com.br/wsdl" 
	xmlns:soap-env="http://schemas.xmlsoap.org/wsdl/soap/" 
	xmlns:wsdl="http://www.w3.org/2003/06/wsdl" 
	xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" 
	targetNamespace="http://www.sit.com.br/wsdl">

	
	
<!-- ### TYPES ###  -->	

<types>

	<xsd:complexType  name="WSDLObject">
		<xsd:sequence>
			<xsd:element minOccurs="1" name="param1" type="xsd:string"/>
			<xsd:element minOccurs="1" name="param2" type="xsd:string"/>
			<xsd:element minOccurs="1" name="param3" type="xsd:string"/>
		</xsd:sequence>
	</xsd:complexType>

</types>



<!-- ### [END] TYPES [END] ###  -->	
	
	
<!-- ### MESSAGES ###  -->	
	
<message name="sendRequest">
	<part name="arg1" type="tns:WSDLObject"/>
</message>
<message name="sendResponse">
	<part name="result" type="tns:WSDLObject"/>
</message>


<!-- ### [END] MESSAGES [END] ###  -->	


<!-- ### PORTTYPE ### -->

<portType name="Type_ports">

	<operation name="send">
		<input message="tns:sendRequest"/>
		<output message="tns:sendResponse"/>
	</operation>
	
</portType>

<!-- ### [END] PORTTYPE [END] ### -->

<!-- ### BINDING ### -->

<binding name="Type_bind" type="tns:Type_ports">

	<soap-env:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
	<operation name="send">
		<soap-env:operation soapAction="Type_ports#send"/>
		<input name="sendRequest">
			<soap-env:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Types" use="literal" />
		</input>
		<output name="sendResponse">
			<soap-env:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Types" use="literal" />
		</output>
	</operation>
	
</binding>

<!-- ### [END] BINDING [END] ### -->

<service name="Type_service">
	<documentation>Web-Services para operaes matematicas</documentation>
	<port binding="tns:Type_bind" name="Type_port_bind">
		<soap-env:address location="http://10.11.40.177/developers/heitor/ws/teste/teste_ser.php"/>
	</port>
</service>

</definitions>


Expected result:
----------------
RESPONSE FROM SERVER

object(PHPObject)[3]
  public 'prop1' => string 'SERVER_1' (length=8)
  public 'prop2' => string 'SERVER_2' (length=8)
  public 'propc' => string 'SERVER_3' (length=8)
  [methods list]

SOAP RESPONSE

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<result xsi:type="PHPObject">
<prop1>SERVER_1</prop1>
<prop2>SERVER_2</prop2>
<propc>SERVER_3</propc>
</result>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>



Actual result:
--------------
RESPONSE FROM SERVER

object(stdClass)[3]
  public 'prop1' => string 'SERVER_1' (length=8)
  public 'prop2' => string 'SERVER_2' (length=8)
  public 'propc' => string 'SERVER_3' (length=8)

SOAP RESPONSE

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<result xsi:type="PHPObject">
<prop1>SERVER_1</prop1>
<prop2>SERVER_2</prop2>
<propc>SERVER_3</propc>
</result>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-22 14:46 UTC] dmitry@php.net
Your have three errors in your report.

1) In WSDL file you've forgot <schema> tag inside <types> element:

<xsd:schema targetNamespace="http://schemas.nothing.com">
  <xsd:complexType  name="WSDLObject">
    <xsd:sequence>
      <xsd:element minOccurs="1" name="param1" type="xsd:string"/>
      <xsd:element minOccurs="1" name="param2" type="xsd:string"/>
      <xsd:element minOccurs="1" name="param3" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

2) You shuold use "rpc/encoded" instead of "document/literal" encoding, or the envilope won't contain type name and it cannot be used to restore object of proper class.

3) PHPObject ius incompatible with WSDL type. The first one has $prop1 but the second one $param1.



 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 13:01:27 2025 UTC