|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-10-24 18:29 UTC] tony at marston-home dot demon dot co dot uk
Description: ------------ In my WSDL I have a complexType entry which has a maxOccurs set to 1. If I exceed this limit the error message says "SOAP-ERROR: Encoding object has no 'first_name' property" where 'first_name' is the first required field in the enclosed structure. Test script: --------------- WSDL: <xsd:complexType name="ArrayOfContactInfo"> <xsd:sequence> <xsd:element name="contact" type="tns:contact" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="contact"> <xsd:all> <xsd:element name="title" type="xsd:string" minOccurs="0" maxOccurs="1"/> <xsd:element name="first_name" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="middle_name" type="xsd:string" minOccurs="0" maxOccurs="1"/> <xsd:element name="last_name" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:all> </xsd:complexType> Expected result: ---------------- I expect a more meaningful error message such as "More than N occurrences exceeded" Actual result: -------------- The error message is totally misleading. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 19:00:01 2025 UTC |
It's possible that I'm not understanding the issue properly, but it seems like the issue here is that 'first_name' is trying to be accessed on the array of 'contact', which won't map to the type. Replacing ArrayOfContactInfo with: <xsd:complexType name="ArrayOfContactInfo"> <complexContent> <restriction base="SOAP-ENC:Array"> <attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:contact[]"/> </restriction> </complexContent> </xsd:complexType> and removing the extra 'contact' array: 'contacts' => [ '0' => [ 'title' => 'Mr', 'first_name' => 'Joe', 'middle_name' => 'Xavier', 'last_name' => 'Soap', 'contact_role' => 'Account Manager', 'telephone' => '075 40008000' ], '1' => [ 'title' => 'Mrs', 'first_name' => 'Jane', 'last_name' => 'Doe', 'contact_role' => 'Assistant Account Manager', 'telephone' => '075 40008001' ], '2' => [ 'title' => 'Miss', 'first_name' => 'Dee', 'last_name' => 'Meanour', 'contact_role' => 'Deputy Assistant Account Manager', 'telephone' => '075 40008003', ], ], seems like it might be more in line with the expected behavior?Here's what is happening: If maxOccurs is 1 then the PHP value should not be a list. Because there's only possibly one. It doesn't make sense to have a list when there can only be a single entity/value in it. Like having the title be an array("Title") is weird. If maxOccurs is unbounded or >1, PHP does not validate against the count. It just doesn't. If the max is 2 and you give 3 then it will put in all 3 (which you can verify through __getLastRequest). So there's two issues here: 1. That behavior is undocumented. I think it's the most important aspect of this report, so I'm repurposing this as a doc bug. 2. The missing maxOccurs validation. I don't see this as high priority as it doesn't seem that SoapClient has any particular intention to perform validation beyond what is required to serialize the data to XML; maxOccurs when >1 isn't being validated, minOccurs when >1 isn't being validated, and there are probably other rules not being validated either.