php.net |  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
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: tony at prettysimplegames dot com
New email:
PHP Version: OS:

 

 [2015-11-17 09:42 UTC] tony at prettysimplegames dot com
Description:
------------
---
From manual page: http://www.php.net/function.base-convert
---

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($string_in_base_two);
var_dump($string_in_base_thirty_two);
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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-18 01:50 UTC] requinix@php.net
-Type: Feature/Change Request +Type: Documentation Problem -Package: PHP Language Specification +Package: Math related
 [2015-11-18 01:50 UTC] requinix@php.net
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] cmb@php.net
-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] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=338497
Log: fix #70928: base_convert doesn't distinguish capital letter
 [2016-01-15 13:24 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2016-01-15 13:24 UTC] cmb@php.net
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] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=351c52e74c397d3e275a51260760b062731498a8
Log: fix #70928: base_convert doesn't distinguish capital letter
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC