|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69422 json_encode() needs encoding specification
Submitted: 2015-04-10 21:57 UTC Modified: 2015-04-19 22:13 UTC
From: Assigned:
Status: Open Package: JSON related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-04-10 21:57 UTC]
Currently, json_encode() encode PHP int/float/bool as JSON numeric(int/float) and bool. Since JSON numeric does not map to PHP int/float as JSON numeric could be any precision, large numbers need to be stored as "string" which is converted to JSON string.

Some "string" needed to be encoded as numeric. To do that json_encode() needs some kind of specification to encode data as programmer intended.

This could be used as the specification.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-19 22:13 UTC]
Related bug
 [2021-11-01 10:11 UTC] glash dot gnome at gmail dot com
Hello, I propose an incomplete solution but it may solve some problems.

Like array_intersect() we could do :

class ExpectedObject {
  string $test;
  float  $poc;
$obj = json_decode_spec('{"test":1234567890.12345678, "poc": "1Gm", "key":'val'}', ExpectedObject::class, ...);

object(ExpectedObject)#1 {
   test => (string) '1234567890.12345678'
   poc  => (float) 1.0

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Feb 27 15:01:32 2024 UTC