rfc:base_convert_improvements

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:base_convert_improvements [2019/05/18 09:21]
exussum Move to Under Discussion
rfc:base_convert_improvements [2020/08/01 23:53] (current)
carusogabriel RFC was implemented
Line 3: Line 3:
   * Date: 2019-05-15   * Date: 2019-05-15
   * Author: Scott Dutton,php@exussum.co.uk   * Author: Scott Dutton,php@exussum.co.uk
-  * Status: Under Discussion+  * Status: Implemented (in PHP 7.4)
   * First Published at: https://wiki.php.net/rfc/base_convert_improvements   * First Published at: https://wiki.php.net/rfc/base_convert_improvements
  
Line 9: Line 9:
  
 ===== Introduction ===== ===== Introduction =====
-the base_convert family of functions(base_convert, binhex, hexbin etc) are very accepting with their input arguments, you can pass any string to to them and they give a best effort of converting it.+The base_convert family of functions(base_convert, binhex, hexbin etc) are very accepting with their input arguments, you can pass any string to to them and they give a best effort of converting it.
  
 For example base_convert("hello world", 16, 10); will return 237 with no warnings. What this does internally is base_convert("ed", 16, 10);  For example base_convert("hello world", 16, 10); will return 237 with no warnings. What this does internally is base_convert("ed", 16, 10); 
  
-Also negative numbers simply do not work, eg base_convert("-ff", 16, 10); will return 255. (similar to above the "-" gets silently ignored)+Also negative numbers simply do not work, eg base_convert("-ff", 16, 10); will return 255. (similar to above the "-" gets silently ignored).
  
-other functions effected by this +Experienced developers get caught out by this for example  https://gist.github.com/iansltx/4820b02ab276c3306314daaa41573445#file-getlines-php-L9 
-decbin() - Decimal to binary + 
-bindec() - Binary to decimal +In this case literal binary data was the input and the result was 0 (which is expected but not clear) 
-decoct() - Decimal to octal + 
-octdec() - Octal to decimal +Other functions affected by this are: 
-dechex() - Decimal to hexadecimal + 
-hexdec() - Hexadecimal to decimal+  decbin() - Decimal to binary 
 +  bindec() - Binary to decimal 
 +  decoct() - Decimal to octal 
 +  octdec() - Octal to decimal 
 +  dechex() - Decimal to hexadecimal 
 +  hexdec() - Hexadecimal to decimal 
 + 
 + 
 + 
 +Other programming languages behave in a a similar way to this proposal 
 + * Javascript - https://jsfiddle.net/c16b4usp/ 
 + * Python - https://repl.it/repls/OliveBlushingModem 
 + * Go - https://play.golang.org/p/aLWg15c00Fy 
 + 
 +Javascript does work with larger numbers correctly, Python and Go work in a way which would be similar to PHP if this change was made.
  
  
Line 48: Line 62:
 This currently breaks a fair amount of unit tests that I will need to update if this change is accepted.  The unit tests are around extreme values. This currently breaks a fair amount of unit tests that I will need to update if this change is accepted.  The unit tests are around extreme values.
  
-This issue has been worked around in userland PHP for example+A secondary BC change would be people who have worked around this in userland code for example 
 https://stackoverflow.com/a/7051224/1281385 https://stackoverflow.com/a/7051224/1281385
  
 This change will break these work arounds This change will break these work arounds
  
 +Would suggest PHP8 for this change
  
  
Line 82: Line 98:
  
 ===== Future Scope ===== ===== Future Scope =====
-N/A+Allow base_convert to allow any length input and not be restricted to a 64 bit int type
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
-Include these so readers know where you are heading and can discuss the proposed voting options.+2 votes 
 +=== Error on ignored characters === 
 +This vote will be to raise a E_DEPRECATED warning for PHP 7.4. Raising to be an InvalidArgumentException in PHP 8 
 + 
 +=== Allow negative arguments === 
 +This vote will allow negative arguments in PHP 8
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
 https://github.com/php/php-src/pull/3911 https://github.com/php/php-src/pull/3911
  
-===== Implementation ===== 
-After the project is implemented, this section should contain  
-  - the version(s) it was merged into 
-  - a link to the git commit(s) 
-  - a link to the PHP manual entry for the feature 
-  - a link to the language specification section (if any) 
  
 +===== Vote =====
 +Started 19th June 2019. Ends 3rd July 2019
 +<doodle title="Raise deprecated error in 7.4 and raise to exception in PHP 8 for unknown characters" auth="exussum" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
 +
 +<doodle title="Allow negative numbers to be converted in PHP 8" auth="exussum" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
 ===== References ===== ===== References =====
 https://bugs.php.net/bug.php?id=61740 https://bugs.php.net/bug.php?id=61740
rfc/base_convert_improvements.1558171294.txt.gz · Last modified: 2019/05/18 09:21 by exussum