php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65212 problem if pass in numeric string containing a float between 0 and 1
Submitted: 2013-07-06 08:59 UTC Modified: 2020-12-07 12:09 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: iam4webwork at hotmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Math related
PHP Version: Irrelevant OS: Irrelevant
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: iam4webwork at hotmail dot com
New email:
PHP Version: OS:

 

 [2013-07-06 08:59 UTC] iam4webwork at hotmail dot com
Description:
------------
If you pass to base_convert a numeric string like "0.5", to have it converted 
from base 10 to base 16, PHP will interpret the input as decimal 5 and return 
hexadecimal 5.  I suspect that the problem lies internally in the logic of 
_php_math_basetozval.

Test script:
---------------
var_dump(base_convert("0.5",10,16));

Expected result:
----------------
I expected PHP to return a zero just as printf("%x","0.5") and dexhex() do.

Actual result:
--------------
5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-06 17:42 UTC] iam4webwork at hotmail dot com
_php_math_basetozval appears to be source of problem b/c while it mimics strtol, 
unlike strtol it fails to adequately deal with '.' being an illegal character. 
strtol disregards '.' and all subsequent input whereas _php_math_basetozval just 
skips the '.' and processes the next character.
 [2020-12-07 12:09 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-12-07 12:09 UTC] cmb@php.net
That behaves as documented[1]:

| Any invalid characters in number are silently ignored. As of PHP
| 7.4.0 supplying any invalid characters is deprecated.

[1] <https://www.php.net/manual/en/function.base-convert.php#refsect1-function.base-convert-parameters>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 26 00:01:32 2024 UTC