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
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 !
Your email address:
MUST BE VALID
Solve the problem:
10 + 50 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 03:01:27 2024 UTC