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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: staff at newsocialife dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Wed Aug 12 12:01:24 2020 UTC