Req->Doc #70928 [Opn]: base_convert should distinguish capital letter

From: Date: Wed, 18 Nov 2015 01:50:35 +0000
Subject: Req->Doc #70928 [Opn]: base_convert should distinguish capital letter
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12871@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: requinix@php.net Reported by: tony at prettysimplegames dot com Summary: base_convert should distinguish capital letter Status: Open -Type: Feature/Change Request +Type: Documentation Problem -Package: PHP Language Specification +Package: Math related Operating System: All PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#12871) next »