ZF-4437: Float values containing commas are not encoded correctly


A float value such as 10.3 that is represented by 10,3 in some locales is not encoded correctly. The resulting JSON string will contain an extra comma.


Please clarify: was this result obtained using Zend_Json::encode(), or Zend_Json_Encoder::encode()? If the former, do you have ex/tjson installed? The reason I ask is that this may be an upstream (PHP) bug.

Json extension is instaled and loaded:

json support enabled json version 1.2.1

tested on PHP 5.2.5 and 5.2.6 - same output

And test code:

   $data = array ();
   for($i = 1; $i < 10; $i ++) {
       $data [] = rand ( 0, 10 ) / rand ( 2, 9 );
        echo '<pre>'; var_dump ( $data ); echo '</pre>';
        echo '<pre>json_encode'; print_r( json_encode( $data )  ); echo '</pre>';
   echo '<pre>ZJE::e'; print_r ( Zend_Json_Encoder::encode ( $data ) ); echo '</pre>';
   echo '<pre>ZE::e'; print_r ( Zend_Json::encode ( $data ) ); echo '</pre>';

array(9) { [0]=> int(2) [1]=> float(1,14285714286) [2]=> int(3) [3]=> float(1,42857142857) [4]=> float(1,75) [5]=> float(1,33333333333) [6]=> int(0) [7]=> float(1,28571428571) [8]=> float(0,5) }




I'm a bit loathe to alter Zend_Json_Encoder to have different results than json_encode(). Is there a bug filed on to alter this behavior for ext/json? If so, I think we can make the change and indicate in the manual in what version of PHP it is (will be) fixed.

Hmm. Looking at the tests above it looks like json_encode() is working properly and Zend_Json_Encoder is not.



I reproduced this issue and committed a fix in r14400, scheduled for 1.8 release