|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70928 base_convert doesn't distinguish capital letter
Submitted: 2015-11-17 09:42 UTC Modified: 2016-01-15 13:24 UTC
From: tony at prettysimplegames dot com Assigned: cmb (profile)
Status: Closed Package: Math related
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tony at prettysimplegames dot com
New email:
PHP Version: OS:


 [2015-11-17 09:42 UTC] tony at prettysimplegames dot com
From manual page:

base_convert function in the documentation is displayed with a capital letter. The fact that base_convert accept to transform a capital letter and convert it to the same letter in lower case is confusing and can cause serious problem.

If you base_convert from a base A to a base B, and then convert from base B to base A the original string is not the same.

In the ext/standard/math.c file the total base is without capital letters:
PHPAPI zend_string * _php_math_longtobase(zval *arg, int base)
	static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";

Test script:
$original_string = "A1";

$string_in_base_two = base_convert($original_string, 32, 2);
$string_in_base_thirty_two = base_convert($string_in_base_two, 2, 32);

var_dump($original_string == $string_in_base_thirty_two);

Expected result:
- At least update the documentation and add the dictionary "0123456789abcdefghijklmnopqrstuvwxyz" and remove the example with the capital letter.

- At best throw an error/return false when the base_convert function is used with invalid range: 

base_convert("A1", 32, 2) must return false in my opinion.

Actual result:
base_convert("A1", 32, 2) return the same thing as base_convert("a1", 32, 2)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-18 01:50 UTC]
-Type: Feature/Change Request +Type: Documentation Problem -Package: PHP Language Specification +Package: Math related
 [2015-11-18 01:50 UTC]
Rejecting capital letters would be a big BC break. Given how commonly hex strings use capitals, for example, forcing the programmer to remember to strtolower() the input first would be cruel. Really, case sensitivity should only matter if the function supported bases beyond 36 (which it doesn't).

So I'm going to go with a doc bug: change the example to use lowercase, and add a note that the function accepts capitalized input but returns lowercased output.
 [2016-01-15 13:23 UTC]
-Summary: base_convert should distinguish capital letter +Summary: base_convert doesn't distinguish capital letter -Assigned To: +Assigned To: cmb
 [2016-01-15 13:24 UTC]
Automatic comment from SVN on behalf of cmb
Log: fix #70928: base_convert doesn't distinguish capital letter
 [2016-01-15 13:24 UTC]
-Status: Assigned +Status: Closed
 [2016-01-15 13:24 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:07 UTC]
Automatic comment on behalf of cmb
Log: fix #70928: base_convert doesn't distinguish capital letter
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 28 23:01:28 2024 UTC