Doc #70928 [Asn->Csd]: base_convert doesn't distinguish capital letter

From: Date: Fri, 15 Jan 2016 13:24:44 +0000
Subject: Doc #70928 [Asn->Csd]: base_convert doesn't distinguish capital letter
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-13112@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70928&edit=1 ID: 70928 Updated by: cmb@php.net Reported by: tony at prettysimplegames dot com Summary: base_convert doesn't distinguish capital letter -Status: Assigned +Status: Closed Type: Documentation Problem Package: Math related Operating System: All PHP Version: Irrelevant Assigned To: cmb Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2016-01-15 13:24:09] 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 ------------------------------------------------------------------------ [2015-11-18 01:50:34] 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. ------------------------------------------------------------------------ [2015-11-17 09:42:59] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70928&edit=1

« previous php.doc.bugs (#13112) next »