ZF-3900: Returning Arrays of Certain Types

Issue Type: Improvement Created: 2008-08-08T12:12:18.000+0000 Last Updated: 2008-11-13T14:10:24.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: Benjamin Eberlei (beberlei) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Soap_Wsdl

Related issues: - ZF-4713

Attachments: - Zend_Soap_Wsdl.arraySoapEnc.patch


In most applications, when returning an array of data this is restricted to one type. Wouldn't it be a good practice to adopt java language syntax style "type[]" to declare the return type "array of types" in the @return Doc Comment?

This usage is more important in the AutoDiscovery generation of WSDL file than to declare the "correct" return value "array" for generating a PHPdoc API document. I think it could be accepted for usage as syntax description of this types. And although it has been rejected as PHP specific implementation in method headers using it in @return is still a very good practice.

As I can take from the following comment this is also practice in Zend Studio:…


Posted by Marcus Welz (lucidix) on 2008-09-04T16:26:54.000+0000

I've put together a quick hack (Zend_Soap_Wsdl.complexTypeArray.patch attached) that will probably need some cleanup work, but as far as I can tell it generates the desired result. It uses the "type[]" syntax, works with simple and complex types, and even arrays of arrays and so on (that is, you can have a return type of "string[][][]" however deep you desire).

Since the WSDL also allows for specifying minimum and maximum occurrances of elements, I went ahead and implemented that as well in the form of "type[,]". and can be any positive number, or "*". It's probably overkill, not to mention non-standard syntax in the PHP world, but it's also easy to remove from the patch. But if you wanted to declare that a function or method is going to return an array of one to five users, you can use "User[1,5]", and the complexType will be named "User1to5Array".

Posted by Marcus Welz (lucidix) on 2008-09-04T16:40:23.000+0000

Zend_Soap_Wsdl.complexTypeArrayPlain.patch is a simpler version.

Posted by Ing. Jitka Darbujanova (jitka_sunny) on 2008-10-10T01:04:24.000+0000

Thanks, I am voting for this issue. Only small improvement to meet the standards:

Name should be as: ArrayOf, so ArrayOfUser1to5 instead of User1to5Array.

Thanks for patch, I am looking forward this improvement in oficial release!

Posted by Marcus Welz (lucidix) on 2008-10-10T07:43:05.000+0000

To be honest, I'm not exactly confident that my "solutions" are approaching this issue from the right angle at all. These patches are little more than hacks in an attempt to get more than just scalar data types working when interfacing PHP with Java via SOAP. The (first two) patches work, but they essentially describe an array as an object with a property called item, which may be present multiple times (which is what the minOccurs and maxOccurs attributes are for) and will then behave as an array. And apparently that's something that JBoss is happy with, but from what I gather, it's not the correct way to do this. The issue becomes apparent when trying to send such a data structure back to PHP, which will do exactly what was specified; create an object with an 'item' property which then contains the array elements. One could still work with that by implementing ArrayAccess but that's fixing a symptom, not the cause, and I'm digressing...

The proper way, as I understand it, is to use a complexType that uses "soap-enc:Array" as its base, and specify the arrayType attribute, but (and I'm not a Java guy, but from what I gather) apparently JBoss' Web Service implementation does not support soap encoding, so it chokes on this.

Posted by Marcus Welz (lucidix) on 2008-10-10T07:45:40.000+0000

I've attached the arraySoapEnc.patch hack which is using soap-enc:Array to specify arrays. I think this is the correct way to approach arrays from a WSDL standpoint, but it won't work if the other end doesn't support soap encoding.

Posted by Benjamin Eberlei (beberlei) on 2008-11-01T06:00:26.000+0000

Issue resolved, added new Strategy for ComplexType detection "Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence"

Posted by Wil Sinclair (wil) on 2008-11-13T14:10:24.000+0000

Changing issues in preparation for the 1.7.0 release.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.