I’m using php 5.6.8 on ubuntu 12.04, trying to json_encode($arr, JSON_PRESERVE_ZERO_FRACTION)
but JSON_PRESERVE_ZERO_FRACTION
is undefined. I thought maybe it was introduced in php-json 1.3.7+
, so i tried to sudo apt-get install --only-upgrade php5-json
, it tells me i have the newest version of php-json
.
I’m using Ondřej Surý PPA as the source. Anyone have an idea what’s wrong?
Edit
I’ve also checked in php without any application (php -a
), this constant is still undefined. So i don’t think it’s anything app-related.
Advertisement
Answer
Should be available in PHP 5.6.6+.
In case some of your tools complains about missing constant you can add polyfill:
if(!defined('JSON_PRESERVE_ZERO_FRACTION')) { define('JSON_PRESERVE_ZERO_FRACTION', 1024); }