0

I must generate a PHP class for the SOAP following a WSDL specification, and this WSDL has 2 different complex types like this (one is called "method1" and the other "Method1"):

<xs:complexType name="method1">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="tns:Method1"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="Method1">
    <xs:sequence>
      <xs:element name="name" type="xs:long"/>
      <xs:any namespace="##other" processContents="lax"/>
    </xs:sequence>
  </xs:complexType>

So, PHP classes would be generated like this, but I would get the error "Extra content at the end of the document" when the web service is executed, because both classes have the same name.

class method1 {
    /** @var Method1 */
        var $return;
}

class Method1 {
    /** @var int */
    var $name = '';
    /** @var mixed */
    var $any = '';
}

Any way to solve this? The problem is that I must follow the WSDL specification from another company, so it should have these 2 complex types. Thanks

user1695700
  • 71
  • 2
  • 12

1 Answers1

1

You don't need to name the PHP classes identical to the complex types in the WSDL. In fact I would intentionally not do it, because class names must fit into my own (PSR-based) schema for autoloading and coding style.

And there is one nice feature that helps here: The classmap option in the SOAP client. This maps every wanted complex type in the SOAP request and response onto the PHP class representing it.

You would use it like this:

$client = new SoapClient(
    $wsdl, 
    array(
        'classmap' => array(
            'method1' => 'YourLowercaseMethod1Class',
            'Method1' => 'YourInitialCapsMethod1Class',
        )
    )
);

If you do it this way, any response you get will not use the default stdClass for these complex types, but the defined PHP class, which allows for epic wins in regard to autocompletion.

Sven
  • 69,403
  • 10
  • 107
  • 109