Bug #61537 [NEW]: json_encode() incorrectly truncates/discards information
| From: | joey@php.net | Date: | Wed, 28 Mar 2012 05:01:01 +0000 |
| Subject: | Bug #61537 [NEW]: json_encode() incorrectly truncates/discards information | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-168896@lists.php.net to get a copy of this message | ||
From: joey
Operating system: all
PHP version: 5.4.0
Package: JSON related
Bug Type: Bug
Bug description:json_encode() incorrectly truncates/discards information
Description:
------------
When json_encode() cannot correctly encode its argument into JSON, the
expected
behaviour is that it will return false, and people can check
json_last_error() to
see why it failed. Currently, it will replace all data it could not encode
with
the string 'null'. This can lead to what appears to be silently discarding
data.
Test script:
---------------
<?php
var_dump(json_encode(chr(215)), json_last_error());
Expected result:
----------------
bool(false)
int(5)
Actual result:
--------------
string(4) 'null'
int(5)
--
Edit bug report at https://bugs.php.net/bug.php?id=61537&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61537&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61537&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61537&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=61537&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61537&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=61537&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=61537&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=61537&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=61537&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=61537&r=support
Expected behavior: https://bugs.php.net/fix.php?id=61537&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=61537&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=61537&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=61537&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61537&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=61537&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=61537&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=61537&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=61537&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=61537&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=61537&r=mysqlcfg