ZF-3900: Returning Arrays of Certain Types


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:…


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".

Zend_Soap_Wsdl.complexTypeArrayPlain.patch is a simpler version.

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!

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.

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.

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

Changing issues in preparation for the 1.7.0 release.