Edit report at http://pear.php.net/bugs/bug.php?id=9375&edit=1
ID: 9375
Updated by: [email protected]
Reported By: sylvain at jamendo dot com
Summary: XML_RPC_decode decodes integer as strings in an array
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: XML_RPC
Package Version: 1.5.1
PHP Version: 5.2.0 RC4
-Assigned To:
+Assigned To: danielc
Roadmap Versions:
New Comment:
-Status: Feedback
+Status: No Feedback
-Assigned To:
+Assigned To: danielc
Previous Comments:
------------------------------------------------------------------------
[2010-01-07 15:21:16] danielc
-Status: Open
+Status: Feedback
How can XML_RPC_decode() in PHP cause problems for Python?
------------------------------------------------------------------------
[2007-02-01 08:03:18] siudak at xz dot pl
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();
------------------------------------------------------------------------
[2007-02-01 06:42:09] siudak at xz dot pl
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();
------------------------------------------------------------------------
[2006-11-18 07:28:52] sylvain at jamendo dot com
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
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=9375&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.