php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76884 base_convert restore data not equal origin data
Submitted: 2018-09-15 03:24 UTC Modified: 2018-09-15 03:35 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: aston dot seal at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 7.2.10 OS: centos 7.4
Private report: No CVE-ID: None
 [2018-09-15 03:24 UTC] aston dot seal at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.base-convert
---
PHP Version : PHP 7.2.10 (cli) (built: Sep 11 2018 10:09:51) ( NTS )

when I using base_convert to make a order id for my system, I found it restore my data isn't correct, is it a bug ?


origin_data always not equal recovery_data

Test script:
---------------
$a = '10010'.sprintf('%02d',mt_rand(0,99)).str_pad(str_replace('.', '', microtime(TRUE)), 14, 0, STR_PAD_RIGHT);
echo 'origin_data : '.$a;
echo '<br>';
$b = base_convert($a, 10,36);
echo 'convert_data : '.$b;
echo '<br>';
echo 'recovery_data : '.base_convert($b, 36,10);

Expected result:
----------------
origin_data : 100106615369813329847
convert_data : l4k9ti8ikb4cg
recovery_data : 100106615369813329847

Actual result:
--------------
origin_data : 100106615369813329847
convert_data : l4k9ti8ikb4cg
recovery_data : 100106615369813328882

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-15 03:33 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-09-15 03:33 UTC] requinix@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

> Warning: base_convert() may lose precision on large numbers due to properties related to the internal "double" or
> "float" type used. Please see the Floating point numbers section in the manual for more specific information and
> limitations.

You're trying to generate a unique identifier. There are better methods.
 [2018-09-15 03:34 UTC] aston dot seal at gmail dot com
-Status: Not a bug +Status: Open -Package: *General Issues +Package: Math related
 [2018-09-15 03:34 UTC] aston dot seal at gmail dot com
change package
 [2018-09-15 03:35 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-09-15 03:35 UTC] requinix@php.net
.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 22:01:28 2024 UTC