phpro / soap-client

A general purpose SOAP client for PHP
MIT License
857 stars 175 forks source link

minOccurs=0 and return types #437

Closed staabm closed 2 years ago

staabm commented 2 years ago

Bug Report

Q A
BC Break no
Version 1.7.4

Summary

we use wsdls which define xsd:element .. type="xsd:string" tags including minOccurs=0, which makes these getters of this fields to return null at runtime.

<xsd:element minOccurs="0" maxOccurs="1" name="recId" type="xsd:string"/>

Current behavior

soap-client generates getters for these properties, with a regular @return string instead @return null|string

// ...
    /**
     * @return string
     */
    public function getGetRecIdFromKeyResult()
    {
        return $this->GetRecIdFromKeyResult;
    }
// ...

How to reproduce

generate a soap client for http://webconnector.tso.de/api/wsdl/SalesOrder.wsdl

Expected behavior

when minOccurs=0 the return-type should be nullable:

// ...
    /**
     * @return null|string
     */
    public function getGetRecIdFromKeyResult()
    {
        return $this->GetRecIdFromKeyResult;
    }
// ...
veewee commented 2 years ago

Ext-soap does not provide that information. https://github.com/phpro/soap-client/blob/master/docs/known-issues/ext-soap.md#occurs

Currently, this issue can be avoided by not generating too strict types in the soap-client and optionally by using the IteratorAssembler.

This issue has been reported a few times: #346, #231, #282, #344, ...

Until we have a better way of getting the data back from the WSDL, there is no simple solution for this.

staabm commented 2 years ago

thx for the response.

Currently, this issue can be avoided by not generating too strict types in the soap-client and optionally by using the IteratorAssembler.

this will only work for 1:n or m:n relationships between objects I guess, not for a scalar value like string?

This issue has been reported a few times: #346, #231, #282, #344, ...

Until we have a better way of getting the data back from the WSDL, there is no simple solution for this.

I see. I can now remember, that we talked about that already in the past :).

veewee commented 2 years ago

this will only work for 1:n or m:n relationships between objects I guess, not for a scalar value like string?

Yes, that is only for multiple entries of the datatype. It could also work on scalars iirc. You might be able to test it on your service.

veewee commented 1 year ago

Hello,

We noticed this issue got reported many times and want to tackle it at its core! Therefore, we've planned a project that will work on better types support. It’s going to be a huge project, so we are looking for ways to make development possible during our business hours instead of in our developers precious spare time.

In case you want this feature as badly as us: find out how you can support this project here 💚!