|  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
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
 [2013-07-06 08:59 UTC] iam4webwork at hotmail dot com
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 

Test script:

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

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


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]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-12-07 12:09 UTC]
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] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 17:01:31 2024 UTC