rfc:json_preserve_fractional_part

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:json_preserve_fractional_part [2014/12/25 19:03] jrbassorfc:json_preserve_fractional_part [2015/04/09 16:59] – PFP was actually implemented, via jsond ajf
Line 1: Line 1:
-====== PHP RFC: JSON Preserve Fractional Part ====== +====== PHP RFC: Preserve Fractional Part in JSON encode ====== 
-  * Version: 0.1+  * Version: 1.1
   * Date: 2014-12-25   * Date: 2014-12-25
   * Author: Juan Basso, jrbasso@gmail.com   * Author: Juan Basso, jrbasso@gmail.com
-  * Status: Draft+  * Status: Implemented (PHP 7.0)
   * First Published at: http://wiki.php.net/rfc/json_preserve_fractional_part   * First Published at: http://wiki.php.net/rfc/json_preserve_fractional_part
  
Line 18: Line 18:
 Testing the same behavior in other languages it shows that Go and JavaScript encode 10.0 to 10, but Python, C (lib jansson) and Ruby encode it to 10.0. Testing the same behavior in other languages it shows that Go and JavaScript encode 10.0 to 10, but Python, C (lib jansson) and Ruby encode it to 10.0.
  
-The goal of this RFC is propose a new json_encode option called JSON_PRESERVE_FRACTIONAL_PART to allow the same behavior of other languages and allowing the symmetry of the encode and decode. See below what changes:+The goal of this RFC is propose a new json_encode option called JSON_PRESERVE_ZERO_FRACTION to allow the same behavior of other languages and allowing the symmetry of the encode and decode. See below what changes:
  
 <PHP> <PHP>
 // Currently // Currently
 echo json_encode(10.0); // Output 10 echo json_encode(10.0); // Output 10
 +echo json_encode(10.1); // Output 10.1
 var_dump(json_decode(json_encode(10.0))); // Output int(10) var_dump(json_decode(json_encode(10.0))); // Output int(10)
 var_dump(10.0 === json_decode(json_encode(10.0))); // Output bool(false) var_dump(10.0 === json_decode(json_encode(10.0))); // Output bool(false)
Line 28: Line 29:
 // Proposed // Proposed
 echo json_encode(10.0); // Output 10 echo json_encode(10.0); // Output 10
-echo json_encode(10.0, JSON_PRESERVE_FRACTIONAL_PART); // Output 10.0 +echo json_encode(10.1); // Output 10.1 
-var_dump(json_decode(json_encode(10.0, JSON_PRESERVE_FRACTIONAL_PART))); // Output double(10) +echo json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION); // Output 10.0 
-var_dump(10.0 === json_decode(json_encode(10.0, JSON_PRESERVE_FRACTIONAL_PART))); // Output bool(true)+echo json_encode(10.1, JSON_PRESERVE_ZERO_FRACTION); // Output 10.1 
 +var_dump(json_decode(json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION))); // Output double(10) 
 +var_dump(10.0 === json_decode(json_encode(10.0, JSON_PRESERVE_ZERO_FRACTION))); // Output bool(true)
 </PHP> </PHP>
  
Line 69: Line 72:
  
 ==== New Constants ==== ==== New Constants ====
-JSON_PRESERVE_FRACTIONAL_PART: Preserve the fraction part of float numbers with zero as decimal part.+JSON_PRESERVE_ZERO_FRACTION: Preserve the fraction part of float numbers with zero as decimal part.
  
 ==== Performance ==== ==== Performance ====
Line 105: Line 108:
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
 This RFC requires a 50%+1 majority. This RFC requires a 50%+1 majority.
 +
 +<doodle title="Preserve Fractional Part in JSON encode" auth="jrbasso" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
 +
 +  * Voting opened: 2015-01-11 02:55 UTC
 +  * Voting closes: 2015-01-18 02:55 UTC
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
 Currently implemented on https://github.com/php/php-src/pull/642 Currently implemented on https://github.com/php/php-src/pull/642
 +
 +===== Implementation =====
 +
 +Merged into jsond: https://github.com/bukka/php-src/pull/1
 +
 +jsond merged into 7.0: https://github.com/php/php-src/pull/993
  
 ===== Rejected Features ===== ===== Rejected Features =====
 None so far. None so far.
rfc/json_preserve_fractional_part.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1