|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-10-29 12:47 UTC] max dot bilyk at gmail dot com
Description:
------------
When transferring via SOAP associative arrays which have elements with NULL value these elements are lost. At the same time f.e. empty strings are transferred normally. Properities of objects with NULL value are also transferred OK. The problem is that indices of associative arrays are also informative as well as their values, therefore it's a loss of significant information.
Another example: in case of data fetch from database into associative array we often have array elements with NULL value, and when fetching multiple rows each time the structure of array will be different
while we expect it to be the same after transfer via SOAP.
P.S. This case is in non-WSDL mode.
Reproduce code:
---------------
---- SOAP Server ---
class foo {
function bar() {
return array('a' => 1, 'b' => NULL, 'c' => 2, 'd'=>'');
}
}
$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->setClass("foo");
$server->handle();
---- SOAP Client ---
$client = new SoapClient(NULL, array('location'=>
"http://...../server.php",
"uri" => "http://test-uri/",
"trace" => 1,
"exceptions" => 1));
$result = $client->bar();
print_r($result);
Expected result:
----------------
array (
'a' => 1,
'b' => NULL
'c' => 2
'd' => '',
)
Actual result:
--------------
array (
'a' => 1,
'c' => 2
'd' => '',
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 19:00:01 2025 UTC |
I send a pache for this bug. This patch remove "if(Z_TYPE_PP(temp_data) != IS_NULL)" block. ------------------------------------------------------- +++ php_encoding.c 2009-01-16 16:28:43.000000000 +0900 @@ -2638,33 +2638,33 @@ ulong int_val; zend_hash_get_current_data(data->value.ht, (void **)&temp_data); - if (Z_TYPE_PP(temp_data) != IS_NULL) { - item = xmlNewNode(NULL, BAD_CAST("item")); - xmlAddChild(xmlParam, item); - key = xmlNewNode(NULL, BAD_CAST("key")); - xmlAddChild(item,key); - if (zend_hash_get_current_key(data->value.ht, &key_val, &int_val, FALSE) == HASH_KEY_IS_STRING) { - if (style == SOAP_ENCODED) { - set_xsi_type(key, "xsd:string"); - } - xmlNodeSetContent(key, BAD_CAST(key_val)); - } else { - smart_str tmp = {0}; - smart_str_append_long(&tmp, int_val); - smart_str_0(&tmp); - - if (style == SOAP_ENCODED) { - set_xsi_type(key, "xsd:int"); - } - xmlNodeSetContentLen(key, BAD_CAST(tmp.c), tmp.len); - smart_str_free(&tmp); + item = xmlNewNode(NULL, BAD_CAST("item")); + xmlAddChild(xmlParam, item); + key = xmlNewNode(NULL, BAD_CAST("key")); + xmlAddChild(item,key); + if (zend_hash_get_current_key(data->value.ht, &key_val, &int_val, FALSE) == HASH_KEY_IS_STRING) { + if (style == SOAP_ENCODED) { + set_xsi_type(key, "xsd:string"); } + xmlNodeSetContent(key, BAD_CAST(key_val)); + } else { + smart_str tmp = {0}; + smart_str_append_long(&tmp, int_val); + smart_str_0(&tmp); - xparam = master_to_xml(get_conversion((*temp_data)->type), (*temp_data), style, item); + if (style == SOAP_ENCODED) { + set_xsi_type(key, "xsd:int"); + } + xmlNodeSetContentLen(key, BAD_CAST(tmp.c), tmp.len); - xmlNodeSetName(xparam, BAD_CAST("value")); + smart_str_free(&tmp); } + + xparam = master_to_xml(get_conversion((*temp_data)->type), (*temp_data), style, item); + + xmlNodeSetName(xparam, BAD_CAST("value")); + zend_hash_move_forward(data->value.ht); } }