Issue Details (XML | Word | Printable)

Key: ZF-3900
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Benjamin Eberlei
Reporter: Benjamin Eberlei
Votes: 4
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Returning Arrays of Certain Types

Created: 08/Aug/08 12:12 PM   Updated: 13/Nov/08 02:10 PM   Resolved: 01/Nov/08 06:00 AM
Return to search "Fixed in 1.5.1"
Component/s: Zend_Soap_Wsdl
Affects Version/s: 1.6.0RC1
Fix Version/s: 1.7.0

Time Tracking:
Not Specified

File Attachments: 1. Text File Zend_Soap_Wsdl.arraySoapEnc.patch (3 kB)
2. Text File Zend_Soap_Wsdl.complexTypeArray.patch (3 kB)
3. Text File Zend_Soap_Wsdl.complexTypeArrayPlain.patch (2 kB)

Issue Links:
Dependency
 
Duplicate
 


 Description  « Hide

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 php.net comment this is also practice in Zend Studio:
http://de2.php.net/manual/en/function.soap-soapserver-construct.php#84772



Marcus Welz added a comment - 04/Sep/08 04:26 PM

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[<min>,<max>]". <min> and <max> 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".


Marcus Welz added a comment - 04/Sep/08 04:40 PM

Zend_Soap_Wsdl.complexTypeArrayPlain.patch is a simpler version.


Ing. Jitka Darbujanova added a comment - 10/Oct/08 01:04 AM

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

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

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


Marcus Welz added a comment - 10/Oct/08 07:43 AM

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.


Marcus Welz added a comment - 10/Oct/08 07:45 AM

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.


Benjamin Eberlei added a comment - 01/Nov/08 06:00 AM

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


Wil Sinclair added a comment - 13/Nov/08 02:10 PM

Changing issues in preparation for the 1.7.0 release.