Skip to content

minOccurs="0" uses "null" instead of removing the array if nillable is not set or false #341

@AndreasA

Description

@AndreasA

Describe the bug
If an element uses minOccurs="0" it can be absent from the XML - that is why it is 0.

However, unset is only used if nillable="true", which actually seems a bit wrong as with nillable="true" a null specific element can actually be sent. Though it can also be absent. So for nillable only, it should add null as it is, for minOccurs="0" without nillable it should remove it for null values and for minOccurs="0" with nillable="true" to fully support the spec, it would actually be necessary to differentiate between null and absent, though I guess absent should be fine for that as well.

I think the main issue is https://github.com/WsdlToPhp/DomHandler/blob/2.0.6/src/AbstractElementHandler.php#L166 where it probably should only check for minOccurs="0" and not for both.

Until recently I was using PHP 8.3 and there such an attribute seems to have not been sent by the SoapClient anyway. However, after updating to PHP 8.4 the elment is added. Seems to be a change in the SoapClient, but I could not find out when this was changed.

To Reproduce
Steps to reproduce the behavior:

  • During the package generation? Use a wsdl with e.g. a string element or dateTime element that has minOccurs="0" but no nillable attribute.
  • During the usage of the generated package? The value for that attribute is set to null (by default and also if null is provided) instead of unset.

Expected behavior

  • For minOccurs="0" remove the element if null is provided - independent of nillable attribute (it should be done for nillable true and false as the element can be absent in both scenarios). Especially minOccurs="0" without nillable="true" does not actually allow null here.
  • if nillable="true" and minOccurs > 0 keep null, if null is provided.
  • Optionally if minOccurs="0" and nillable="true" add a method nil which explicitely sets null for the nillable property.

Additional context

This behavior might be somehow to related to an older issue #48 where the removal was for minOccurs="0" and nillable="true" was added.

However, that same behavior has to actually be used for minOccurs="0" as well and actually nillable="true" should allow an override to provide null as well (though I guess in most cases it is fine to just not send a value then as well).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions