Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.5

Bug #9375 XML_RPC_decode decodes integer as strings in an array
Submitted: 2006-11-18 12:28 UTC
From: sylvain at jamendo dot com Assigned: danielc
Status: No Feedback Package: XML_RPC (version 1.5.1)
PHP Version: 5.2.0 RC4 OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 44 + 38 = ?

 
 [2006-11-18 12:28 UTC] sylvain at jamendo dot com (sylvain)
Description: ------------ With 1.5.1, XML_RPC_decode(array(int(3))) = array("3") as a string. I know "php is a typeless language" etc.. but this breaks APIs that are used by other XML_RPC implementations in languages like Python that are typed. Test script: --------------- $msg = new XML_RPC_Message("dummymethod"); $rep = $msg->parseResponse('HTTP/1.1 200 OK Date: Sat, 18 Nov 2006 11:00:57 GMT Server: Apache/2.2.3 (Unix) Connection: close Content-Type: text/xml; charset=UTF-8.'."\r\n\r\n".'<?xml version="1.0" encoding="UTF-8"?> <methodResponse> <params> <param> <value><array> <data> <value><int>42</int></value> </data> </array></value> </param> </params> </methodResponse>'); $p=$rep->value(); $d=XML_RPC_decode($p); echo gettype($d[0]); Expected result: ---------------- int Actual result: -------------- string

Comments

 [2007-02-01 11:42 UTC] siudak at xz dot pl (Piotr Siudak)
Well, this function is quite useful when it actually works. Here is my patch, maybe somebody will find it useful. Index: RPC.php =================================================================== RCS file: /repository/pear/XML_RPC/RPC.php,v retrieving revision 1.101 diff -u -r1.101 RPC.php --- RPC.php 28 Oct 2006 16:42:34 -0000 1.101 +++ RPC.php 1 Feb 2007 11:30:38 -0000 @@ -1972,8 +1972,14 @@ $kind = $XML_RPC_val->kindOf(); if ($kind == 'scalar') { - return $XML_RPC_val->scalarval(); - + switch ($XML_RPC_val->scalartyp()) { + case 'int': + return (int)$XML_RPC_val->scalarval(); + case 'double': + return (float)$XML_RPC_val->scalarval(); + default: + return $XML_RPC_val->scalarval(); + } } elseif ($kind == 'array') { $size = $XML_RPC_val->arraysize(); $arr = array();
 [2007-02-01 13:03 UTC] siudak at xz dot pl (Piotr Siudak)
OK, I forgot booleans. do it would go like this Index: RPC.php =================================================================== RCS file: /repository/pear/XML_RPC/RPC.php,v retrieving revision 1.101 diff -u -r1.101 RPC.php --- RPC.php 28 Oct 2006 16:42:34 -0000 1.101 +++ RPC.php 1 Feb 2007 12:01:18 -0000 @@ -1970,10 +1970,19 @@ function XML_RPC_decode($XML_RPC_val) { $kind = $XML_RPC_val->kindOf(); if ($kind == 'scalar') { - return $XML_RPC_val->scalarval(); - + switch ($XML_RPC_val->scalartyp()) { + case 'int': + return (int)$XML_RPC_val->scalarval(); + case 'double': + return (float)$XML_RPC_val->scalarval(); + case 'boolean' : + return (bool)$XML_RPC_val->scalarval(); + default: + return $XML_RPC_val->scalarval(); + } } elseif ($kind == 'array') { $size = $XML_RPC_val->arraysize(); $arr = array();
 [2010-01-07 20:21 UTC] danielc (Daniel Convissor)
-Status: Open +Status: Feedback
How can XML_RPC_decode() in PHP cause problems for Python?
 [2011-08-27 06:20 UTC] danielc (Daniel Convissor)
-Status: Feedback +Status: No Feedback -Assigned To: +Assigned To: danielc