β.εηοιτ.βε
β.εηοιτ.βε

Reputation: 39159

Create an empty object or array from a complexType

Knowing I have some complexType defined in a wsdl I can access through SOAP via http://www.example.com/webservice?wsdl and that this web service does declare complexType like this (this is only a snippet of the wsdl) :

<xsd:complexType name="customer">
    <xsd:sequence>
        <xsd:element name="firstname" type="xsd:string" minOccurs="0" />
        <xsd:element name="lastname" type="xsd:string" minOccurs="0" />
        <xsd:element name="address" type="typens:address" minOccurs="0" />
    </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="address">
    <xsd:sequence>
        <xsd:element name="street" type="xsd:string" minOccurs="0" />
        <xsd:element name="city" type="xsd:string" minOccurs="0" />
        <xsd:element name="postcode" type="xsd:string" minOccurs="0" />
        <xsd:element name="country" type="xsd:string" minOccurs="0" />
    </xsd:sequence>
</xsd:complexType>

Is there an easy way via SOAP in PHP to create an empty array or object which will be an instance of this complexType ?

The expected behaviour is to have then

object(stdClass)[1]
  public 'firstname' => null
  public 'lastname' => null
  public 'address' => 
    object(stdClass)[2]
      public 'street' => null
      public 'city' => null
      public 'postcode' => null
      public 'country' => null

Or

array (size=3)
  'firstname' => null
  'lastname' => null
  'address' => 
    array (size=4)
      'street' => null
      'city' => null
      'postcode' => null
      'country' => null

I had a look to SoapParam and SoapVar documentation, but they both lack of a proper documentation so I can not seems to figure out if those do that.

Upvotes: 1

Views: 650

Answers (1)

Plamen G
Plamen G

Reputation: 4759

There is a project on Github that aims to resolve this same exact issue.

Check out WSDL2PHPGenerator and see if it does what you want (the project is alive and kicking and has about 3000 installations in the last month alone, so I think it is a safe bet). According to its page it takes a WSDL file and outputs class files ready to use.

Hope this helps! Good luck.

Upvotes: 1

Related Questions