HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/opt/cloudlinux/alt-php74/root/usr/share/pear/test/jsond/tests/bug50224.phpt
--TEST--
bug #50224 (json_encode() does not always encode a float as a float)
--SKIPIF--
<?php if (!extension_loaded("jsond")) print "skip"; ?>
--FILE--
<?php
require_once "bootstrap.inc";

echo "* Testing JSON output\n\n";
var_dump($jsond_encode(12.3, jsond_constant('PRESERVE_ZERO_FRACTION')));
var_dump($jsond_encode(12, jsond_constant('PRESERVE_ZERO_FRACTION')));
var_dump($jsond_encode(12.0, jsond_constant('PRESERVE_ZERO_FRACTION')));
var_dump($jsond_encode(0.0, jsond_constant('PRESERVE_ZERO_FRACTION')));
var_dump($jsond_encode(array(12, 12.0, 12.3), jsond_constant('PRESERVE_ZERO_FRACTION')));
var_dump($jsond_encode((object)array('float' => 12.0, 'integer' => 12),
    jsond_constant('PRESERVE_ZERO_FRACTION')));

echo "\n* Testing encode/decode symmetry\n\n";

var_dump($jsond_decode($jsond_encode(12.3, jsond_constant('PRESERVE_ZERO_FRACTION'))));
var_dump($jsond_decode($jsond_encode(12, jsond_constant('PRESERVE_ZERO_FRACTION'))));
var_dump($jsond_decode($jsond_encode(12.0, jsond_constant('PRESERVE_ZERO_FRACTION'))));
var_dump($jsond_decode($jsond_encode(0.0, jsond_constant('PRESERVE_ZERO_FRACTION'))));
var_dump($jsond_decode($jsond_encode(array(12, 12.0, 12.3),
    jsond_constant('PRESERVE_ZERO_FRACTION'))));
var_dump($jsond_decode($jsond_encode((object)array('float' => 12.0, 'integer' => 12),
    jsond_constant('PRESERVE_ZERO_FRACTION'))));
var_dump($jsond_decode($jsond_encode((object)array('float' => 12.0, 'integer' => 12),
    jsond_constant('PRESERVE_ZERO_FRACTION')), true));
?>
--EXPECTF--
* Testing JSON output

string(4) "12.3"
string(2) "12"
string(4) "12.0"
string(3) "0.0"
string(14) "[12,12.0,12.3]"
string(27) "{"float":12.0,"integer":12}"

* Testing encode/decode symmetry

float(12.3)
int(12)
float(12)
float(0)
array(3) {
  [0]=>
  int(12)
  [1]=>
  float(12)
  [2]=>
  float(12.3)
}
object(stdClass)#%d (2) {
  ["float"]=>
  float(12)
  ["integer"]=>
  int(12)
}
array(2) {
  ["float"]=>
  float(12)
  ["integer"]=>
  int(12)
}