rfc:base_convert_improvements
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:base_convert_improvements [2019/05/15 20:42] – created exussum | rfc:base_convert_improvements [2020/04/12 20:13] – Fix typo (effected should be affected) theodorejb | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2019-05-15 | * Date: 2019-05-15 | ||
* Author: Scott Dutton, | * Author: Scott Dutton, | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | the base_convert family of functions(base_convert, | + | The base_convert family of functions(base_convert, |
For example base_convert(" | For example base_convert(" | ||
- | Also negative numbers simply do not work, eg base_convert(" | + | Also negative numbers simply do not work, eg base_convert(" |
+ | |||
+ | Experienced developers get caught out by this for example | ||
+ | |||
+ | In this case literal binary data was the input and the result was 0 (which is expected but not clear) | ||
+ | |||
+ | Other functions affected by this are: | ||
+ | |||
+ | * 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:// | ||
+ | * Python - https:// | ||
+ | * Go - https:// | ||
+ | |||
+ | 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. | ||
+ | |||
===== Proposal ===== | ===== Proposal ===== | ||
- | II propose two changes to the base_convert family of functions. | + | I propose two changes to the base_convert family of functions. |
+ | |||
+ | === Error on ignored characters === | ||
+ | When passed arguments that base_convert will ignore, also give a warning to the user informing them their input was incorrect. | ||
+ | There is an exception in place for the second char, if base is 16 ' | ||
- | === Error on truncation === | ||
- | When passed arguments that base_convert will ignore, also give a warning to the user. | ||
- | There is an exception in place for the second char, if base is 16 x is allowed eg 0xff, base 2 allows b and base 8 allows o. | ||
This can be raised to a full exception for a later PHP version (eg PHP 8) | This can be raised to a full exception for a later PHP version (eg PHP 8) | ||
Line 28: | Line 54: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | === Error on truncation | + | === Error on ignored characters |
No BC breaks for a warning, in the case of an exception there will be a BC break - Would suggest PHP 8 for this. | No BC breaks for a warning, in the case of an exception there will be a BC break - Would suggest PHP 8 for this. | ||
Line 34: | Line 60: | ||
base_convert currently in the backend has a zend_ulong as its representation. We would need a zend_long. This will change the behavior of numbers in the range 9223372036854775807 - 18446744073709551615 but will allow negative numbers. | base_convert currently in the backend has a zend_ulong as its representation. We would need a zend_long. This will change the behavior of numbers in the range 9223372036854775807 - 18446744073709551615 but will allow negative numbers. | ||
- | This currently breaks a fair amount of unit tests that I will need to update if this change is accepted. | + | This currently breaks a fair amount of unit tests that I will need to update if this change is accepted. |
+ | |||
+ | A secondary BC change would be people who have worked around this in userland code for example | ||
+ | |||
+ | https:// | ||
+ | |||
+ | This change will break these work arounds | ||
+ | |||
+ | Would suggest PHP8 for this change | ||
Line 64: | 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:// | https:// | ||
- | ===== Implementation ===== | ||
- | After the project is implemented, | ||
- | - 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=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== References ===== | ===== References ===== | ||
https:// | https:// |
rfc/base_convert_improvements.txt · Last modified: 2020/08/01 23:53 by carusogabriel