php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63152 json_encode does not work on binary strings
Submitted: 2012-09-24 15:14 UTC Modified: 2012-09-24 16:50 UTC
From: staff at newsocialife dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.3.17 OS: Ubuntu
Private report: No CVE-ID: None
 [2012-09-24 15:14 UTC] staff at newsocialife dot com
Description:
------------
So, I have an array witch doesn't encode right in json...
( look the example script... )

Test script:
---------------
$a = Array (
    "password" => "SeRjQRVUglkeM‰‰P9L7NsjKXOY", //it's encrypted with a custom encryption system
    "id" => 0
);
echo json_encode($a);

Expected result:
----------------
{"password":"SeRjQRVUglkeM‰‰P9L7NsjKXOY","id":0}

Actual result:
--------------
{"password":null,"id":0}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-24 15:24 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-09-24 15:24 UTC] rasmus@php.net
JSON as per RFC-4626 cannot encode arbitrary binary data. Everything you pass to 
json_encode() must be valid Unicode. json_last_error() would have told you this.
 [2012-09-24 16:50 UTC] nikic@php.net
-Summary: Json is going stupid +Summary: json_encode does not work on binary strings
 [2012-09-24 16:50 UTC] nikic@php.net
Also, would be nice if you could provide a more meaningful title next time :) Btw, if you want to encode binary data as JSON (or basically anything else) you should first base64_encode it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 11 23:01:29 2024 UTC