PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_Wddx » Bug #5016

preceeding zeroes truncated in string

Details

Submitted2005-08-05 18:51 UTC
Fromfrymaster at linuxmail dot org
Assignedalan_k
StatusClosed
PackageXML_Wddx
PHP Version4.3.9
OSLinux Centos 4.0
Roadmaps(Not assigned)

Comments

[2005-08-05 18:51 UTC] frymaster at linuxmail dot org

Description:
------------
in xml_wddx 1.0.1:

a string of numbers with a preceeding zero, ie. "0677", is automatically converted to type "number" at serialization, thus eliminating the zero.

the code that explicitly casts strings of digits to numbers is located on line 102 and reads:

if ( is_numeric ($value) && (intval(0+$value) == $value) )
return "<number>$value</number>";

this bug occurrs even if the string of digits is explicitly cast as a string prior to serialization.

grant horwood

Test script:
---------------
require_once "XML/Wddx.php";

$wddx_parser = new XML_Wddx();

$test_array = array((string)"098", (string)"0098", "0098R");

print_r($test_array);

$some_wddx = $wddx_parser->serialize($test_array);

print_r($some_wddx);

$back_test_array = $wddx_parser->deserialize($some_wddx);

print_r($back_test_array);

Expected result:
----------------
Array
(
[0] => 098
[1] => 0098
[2] => 0098R
)
<wddxPacket version='1.0'><header/><data>
<array length='3'>
<string>098</string>
<string>0098</string>
<string>0098R</string>
</array>
</data></wddxPacket>
Array
(
[0] => 098
[1] => 0098
[2] => 0098R
)

Actual result:
--------------
Array
(
[0] => 098
[1] => 0098
[2] => 0098R
)
<wddxPacket version='1.0'><header/><data>
<array length='3'>
<number>098</number>
<number>0098</number>
<string>0098R</string>
</array>
</data></wddxPacket>
Array
(
[0] => 98 <- where are my zeroes?
[1] => 98
[2] => 0098R
)