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

Issue Type: Bug Created: 2008-10-01T03:01:48.000+0000 Last Updated: 2009-03-20T07:58:01.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Christoph Dorn (cadorn) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Json

Related issues: Attachments:


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.


Posted by Matthew Weier O'Phinney (matthew) on 2008-10-01T06:02:02.000+0000

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.

Posted by Christoph Dorn (cadorn) on 2008-10-02T13:35:22.000+0000

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 ''; var_dump ( $data ); echo '';
        echo 'json_encode'; print_r( json_encode( $data )  ); echo '';
   echo 'ZJE::e'; print_r ( Zend_Json_Encoder::encode ( $data ) ); echo '';
   echo 'ZE::e'; print_r ( Zend_Json::encode ( $data ) ); echo '';

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) }




Posted by Matthew Weier O'Phinney (matthew) on 2008-11-07T12:12:28.000+0000

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.

Posted by Christoph Dorn (cadorn) on 2008-11-07T12:21:12.000+0000

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



Posted by Benjamin Eberlei (beberlei) on 2009-03-20T07:58:00.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.