|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79960 json_encode(JSON_NUMERIC_CHECK) works differently between 5.4.x and 7.x
Submitted: 2020-08-12 09:54 UTC Modified: 2020-08-12 10:00 UTC
From: danny at klarity dot tv Assigned: cmb (profile)
Status: Not a bug Package: JSON related
PHP Version: 7.2.33 OS: Centos 8
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.
Block user comment
Status: Assign to:
Bug Type:
From: danny at klarity dot tv
New email:
PHP Version: OS:


 [2020-08-12 09:54 UTC] danny at klarity dot tv
After upgrading from PHP 5.4 to 7.2 (with OS upgrade) the behavior of json_encode with JSON_NUMERIC_CHECK changed.

In 5.4, a hex string was converted to an int.

In 7.2, a hex string is output as a hex string.

Test script:
$ php --version
PHP 5.4.45 (cli) (built: Oct 16 2015 11:02:47)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

$ php --interactive
php > print(json_encode("0xFF", JSON_NUMERIC_CHECK));

$ php --version
PHP 7.2.11 (cli) (built: Oct  9 2018 15:09:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

$ php --interactive
Interactive shell

php > print(json_encode("0xFF", JSON_NUMERIC_CHECK));


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-12 10:00 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-08-12 10:00 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is because hexadecimal strings are no longer considered
numeric as of PHP 7.0.0[1].

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:28 2024 UTC