php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-29 12:49 UTC] max dot bilyk at gmail dot com
Sorry, object properties are OK, so I removed it from "Summary"
 [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-16 14:02 UTC] felipe@php.net
Assigned to maintainer.
 [2009-01-26 11:21 UTC] dmitry@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 20:01:30 2024 UTC