Elements of associative arrays with NULL value are lost
| Bug #46419 | Elements of associative arrays with NULL value are lost | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2008-10-29 12:47 UTC | Modified: | 2009-01-26 11:21 UTC |
|
||||||||||
| From: | max dot bilyk at gmail dot com | Assigned: | dmitry (profile) | |||||||||||
| Status: | Closed | Package: | SOAP related | |||||||||||
| PHP Version: | 5.2.6 | OS: | SuSE SLES 10 | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[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' => '',
)
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2008-10-29 12:49 UTC] max dot bilyk at gmail dot com
[2009-01-16 09:41 UTC] might at nifty dot com
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); } }[2009-01-26 11:21 UTC] dmitry@php.net