|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79189 json_encode with JSON_NUMERIC_CHECK and extra option
Submitted: 2020-01-29 09:32 UTC Modified: -
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dalius dot ulevicius at gmail dot com Assigned:
Status: Open Package: JSON related
PHP Version: 7.4.2 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
46 + 34 = ?
Subscribe to this entry?

 [2020-01-29 09:32 UTC] dalius dot ulevicius at gmail dot com
JSON_NUMERIC_CHECK does not respect the definition of numbers.

I think will be great to add extra option like (JSON_NUMERIC_LEADZERO), to do not trailing zeros at the lead.

Extra reported as a bug many years ago:

Test script:
print_r(json_encode(array("shouldBeString0123456" => "0123456", "shouldBeString+0123456" => "+0123456", "isInt" => "123456"), JSON_NUMERIC_CHECK | JSON_NUMERIC_LEADZERO));

Expected result:

Actual result:
    "shouldBeString0123456":123456,    // Bad with JSON_NUMERIC_CHECK 
    "shouldBeString+0123456":123456,   // Bad with JSON_NUMERIC_CHECK 
    "isInt":123456                     // Good


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 06:03:33 2021 UTC