Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array with one integer key not zero converted to array and not to struct #82

Closed
shushu304 opened this issue May 23, 2021 · 4 comments
Closed

Comments

@shushu304
Copy link

shushu304 commented May 23, 2021

Hello,

I found something very interesting and I even don't know and not sure if it is a bug or this is how it supposed to work.

When having an array with one key that is integer but not 0 - zero ,
it converted to xml array with data-values,
instead of been struct with member node.

example:
array (
0 => 'something',
1 => '15632',
2 => 1395,
3 => '25/05/2021',
4 => array (
4035 => array (
0 => 3600,
1 => 3700,
2 => 4200,
),
),
)

see the 4035 key that in this case represent an id of something, and holds list values.

the output xml of this part is:
<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>update_plan_prices</methodName><params><param><value><string>something</string></value></param><param><value><string>15632</string></value></param><param><value><int>1395</int></value></param><param><value><string>25/05/2021</string></value></param><param><value><array><data><value><array><data><value><int>3600</int></value><value><int>3700</int></value><value><int>4200</int></value></data></array></value></data></array></value></param></params></methodCall>

instead of been converted to:
<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>update_plan_prices</methodName><params><param><value><string>something</string></value></param><param><value><string>15632</string></value></param><param><value><int>1395</int></value></param><param><value><string>25/05/2021</string></value></param><param><value>**<struct><member>**<name>4035</name><value><array><data><value><int>3600</int></value><value><int>3700</int></value><value><int>4200</int></value></data></array></value>**</member></struct>**</value></param></params></methodCall>

I assume it is happening in this part if I'm using XmlWriterSerializer
https://github.com/lstrojny/fxmlrpc/blob/master/src/fXmlRpc/Serializer/XmlWriterSerializer.php#L138

and also if use the NativeSerializer
https://github.com/lstrojny/fxmlrpc/blob/master/src/fXmlRpc/Serializer/NativeSerializer.php
with the build in function xmlrpc_encode_request
https://www.php.net/manual/en/function.xmlrpc-encode-request.php

@shushu304
Copy link
Author

Just adding that this is happening when have more then 1 integers keys in ascending order
i.e 4035, 4036... they will be treated and converted data-values.

If they will be in some randomly order , i.e 4036, 4035 ... they will be converted to structs with member node.

@lstrojny
Copy link
Owner

@shushu304 could you test #84 which should address your issues?

@shushu304
Copy link
Author

Thanks Lars,

I tested and looks ok.

This is what I got for the example I posted:

<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>update_plan_prices</methodName><params><param><value><string>something</string></value></param><param><value><string>15632</string></value></param><param><value><int>1395</int></value></param><param><value><string>15/09/2021</string></value></param><param><value><struct><member><name>4035</name><value><array><data><value><int>3600</int></value><value><int>3700</int></value><value><int>4200</int></value><value><int>4300</int></value></data></array></value></member></struct></value></param></params></methodCall>

And for the comment of more then 1 integers keys in ascending order:
<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>update_plan_prices</methodName><params><param><value><string>something</string></value></param><param><value><string>15632</string></value></param><param><value><int>1395</int></value></param><param><value><string>15/09/2021</string></value></param><param><value><struct><member><name>4034</name><value><array><data><value><int>2500</int></value><value><int>2600</int></value><value><int>2650</int></value><value><int>2700</int></value></data></array></value></member><member><name>4035</name><value><array><data><value><int>3600</int></value><value><int>3700</int></value><value><int>4200</int></value><value><int>4300</int></value></data></array></value></member></struct></value></param></params></methodCall>

@lstrojny
Copy link
Owner

Fixed with #84

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants