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  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
2011-08-27 06:20 UTC
Package:
Bug Type:
Summary:
From: sylvain at jamendo dot com
New email:
PHP Version: Package Version: OS:

 

 [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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2011-08-27 06:20 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!