#46419 [Asn->Csd]: Elements of associative arrays with NULL value are lost
| From: | dmitry@php.net | Date: | Mon, 26 Jan 2009 11:21:10 +0000 |
| Subject: | #46419 [Asn->Csd]: Elements of associative arrays with NULL value are lost | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-133215@lists.php.net to get a copy of this message | ||
ID: 46419
Updated by: dmitry@php.net
Reported By: max dot bilyk at gmail dot com
-Status: Assigned
+Status: Closed
Bug Type: SOAP related
Operating System: SuSE SLES 10
PHP Version: 5.2.6
Assigned To: dmitry
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2009-01-16 14:02:40] felipe@php.net
Assigned to maintainer.
------------------------------------------------------------------------
[2009-01-16 09:41:33] 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);
}
}
------------------------------------------------------------------------
[2008-10-29 12:49:02] max dot bilyk at gmail dot com
Sorry, object properties are OK, so I removed it from "Summary"
------------------------------------------------------------------------
[2008-10-29 12:47:18] 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' => '',
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46419&edit=1