php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: danny at klarity dot tv
New email:
PHP Version: OS:

 

 [2020-08-12 09:54 UTC] danny at klarity dot tv
Description:
------------
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));
255

$ 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));
"0xFF"



Patches

Pull Requests

History

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

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

[1] <https://www.php.net/manual/en/migration70.incompatible.php#migration70.incompatible.strings.hex>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC