# [RFC] [Vote] Base convert changes

- Thread: https://externals.io/message/105980
- Original archive: https://news-web.php.net/php.internals/105980
- Started by Scott Dutton on 2019-06-19T07:24:22+00:00
- Messages: 12
- RFC: Base Convert improvements (Implemented (PHP 7.4)) — https://externals.io/rfc/base_convert_improvements.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #105980 — Scott Dutton — 2019-06-19T07:24:22+00:00

URL: https://externals.io/message/105980#105980

Hi all

I have put my RFC base convert changes to vote this morning

https://wiki.php.net/rfc/base_convert_improvements

Two votes, one to raise a deprecated error in PHP7.4 (raised to 
exception in PHP 8) when base_convert encounters something it doesnt 
know how to convert.

Second vote is to allow negative numbers, eg base_convert('-FF', 16, 
10) would return -255 (this returns 255 currently)

Voting ends 3rd July

Thanks

Scott

---

## #105981 — Joe Watkins — 2019-06-19T07:31:43+00:00

URL: https://externals.io/message/105980#105981

The implementation of this does not look ready, there are conflicts so I
can't test it locally, but last time CI ran there were many failures.

Cheers
Joe



> Hi all
>
> I have put my RFC base convert changes to vote this morning
>
> https://wiki.php.net/rfc/base_convert_improvements
>
> Two votes, one to raise a deprecated error in PHP7.4 (raised to
> exception in PHP 8) when base_convert encounters something it doesnt
> know how to convert.
>
> Second vote is to allow negative numbers, eg base_convert('-FF', 16,
> 10) would return -255 (this returns 255 currently)
>
> Voting ends 3rd July
>
> Thanks
>
> Scott

---

## #105982 — Scott Dutton — 2019-06-19T07:43:33+00:00

URL: https://externals.io/message/105980#105982

Hi Joe,

I will take a look at conflicts. The failures are extreme value checks 
which are a result of allowing the negative numbers. If the negative 
numbers one passes I will fix all tests and add some more for the 
negative values. The tests fail because of the unsigned -> signed change 
(but as you say there were quite a lot of tests).

Would it be easier for 2 prs ? one for each vote ?

Thanks

Scott



> The implementation of this does not look ready, there are conflicts
> so I can't test it locally, but last time CI ran there were many
> failures.
>
> Cheers
> Joe
>
> On Wed, 19 Jun 2019 at 09:24, Scott Dutton <scott@exussum.co.uk> 
> wrote:
>
> > […]
>
>
> Links:
> ------
> [1] https://wiki.php.net/rfc/base_convert_improvements
> [2] http://www.php.net/unsub.php

---

## #105983 — Joe Watkins — 2019-06-19T07:56:46+00:00

URL: https://externals.io/message/105980#105983

There should probably be a PR targeting 7.4 with the implementation of
"Error on ignored characters" as proposed for 7.4, and a PR targeting
master implementing "Error on ignored characters" with exception change and
implementing "Allow negative arguments".

None of these PR's should cause tests to fail, and where new untested
behaviour is introduced the PR should include tests for that.

Cheers
Joe





> Hi Joe,
>
> I will take a look at conflicts. The failures are extreme value checks
> which are a result of allowing the negative numbers. If the negative
> numbers one passes I will fix all tests and add some more for the
> negative values. The tests fail because of the unsigned -> signed change
> (but as you say there were quite a lot of tests).
>
> Would it be easier for 2 prs ? one for each vote ?
>
> Thanks
>
> Scott
>
>
> 
> > […]

---

## #105984 — Joe Watkins — 2019-06-19T08:00:52+00:00

URL: https://externals.io/message/105980#105984

It will likely be easier if the Allow negative numbers implementation
(targetting master only) is entirely separate from the Error on ignored
characters implementation,.

Cheers
Joe



> There should probably be a PR targeting 7.4 with the implementation of
> "Error on ignored characters" as proposed for 7.4, and a PR targeting
> master implementing "Error on ignored characters" with exception change and
> implementing "Allow negative arguments".
>
> None of these PR's should cause tests to fail, and where new untested
> behaviour is introduced the PR should include tests for that.
>
> Cheers
> Joe
>
>
>
> 
>
> > […]

---

## #105985 — Scott Dutton — 2019-06-19T08:05:48+00:00

URL: https://externals.io/message/105980#105985

Hi Joe,

I will have a look at splitting the PR, I am not at a computer where i 
can code today though so will be tomorrow at the earliest.

The Negative numbers will be a fair amount of work to make the tests 
pass, would this still need to be done if the RFC doesnt pass ? I am 
happy to do this work if it looks like it will pass, the reasons it 
fails are outlined in the RFC as BC breaks. The tests seem to test the 
values which make it fail more than I have seen other code use these 
values.

887-939 are ignoring invalid input changes, everything else is negative 
numbers


Hope that helps

Scott


> There should probably be a PR targeting 7.4 with the implementation
> of "Error on ignored characters" as proposed for 7.4, and a PR
> targeting master implementing "Error on ignored characters" with
> exception change and implementing "Allow negative arguments".
>
> None of these PR's should cause tests to fail, and where new untested
> behaviour is introduced the PR should include tests for that.
>
> Cheers
> Joe
>
> On Wed, 19 Jun 2019 at 09:43, Scott Dutton <scott@exussum.co.uk> 
> wrote:
>
> > […]
>
>
> Links:
> ------
> [1] https://wiki.php.net/rfc/base_convert_improvements
> [2] http://www.php.net/unsub.php

---

## #105987 — Nikita Popov — 2019-06-19T08:13:09+00:00

URL: https://externals.io/message/105980#105987

> Hi Joe,
>
> I will have a look at splitting the PR, I am not at a computer where i
> can code today though so will be tomorrow at the earliest.
>
> The Negative numbers will be a fair amount of work to make the tests
> pass, would this still need to be done if the RFC doesnt pass ? I am
> happy to do this work if it looks like it will pass, the reasons it
> fails are outlined in the RFC as BC breaks. The tests seem to test the
> values which make it fail more than I have seen other code use these
> values.
>
> 887-939 are ignoring invalid input changes, everything else is negative
> numbers
>

scripts/dev/bless_tests.php can be used to automatically update expected
test output. Doesn't work for all tests (those with many manual wildcards
for example), but may save you some work.

Nikita


> Hope that helps
>
> Scott
>
> 
> > […]

---

## #105988 — Scott Dutton — 2019-06-19T08:16:07+00:00

URL: https://externals.io/message/105980#105988

Ah thats brilliant, I will take a look at updating the tests when I 
split the PR tomorrow

Thanks Nikita

Scott




> On Wed, Jun 19, 2019 at 10:06 AM Scott Dutton <scott@exussum.co.uk> 
> wrote:
>
> > […]
>
> scripts/dev/bless_tests.php can be used to automatically update
> expected test output. Doesn't work for all tests (those with many
> manual wildcards for example), but may save you some work.
>
> Nikita
>
>  
>
> > […]
>
>
> Links:
> ------
> [1] https://wiki.php.net/rfc/base_convert_improvements
> [2] http://www.php.net/unsub.php

---

## #105989 — me@jhdxr.com — 2019-06-19T13:12:30+00:00

URL: https://externals.io/message/105980#105989

Hi Scott,

Could you clarify what will happen if multiple negative sign occurs. I didn't find it in the RFC.
e.g. base_convert('--ff', 16, 10)

Thanks,
CHU Zhaowei

> -----Original Message-----
> From: Scott Dutton <scott@exussum.co.uk>
> Sent: Wednesday, June 19, 2019 3:24 PM
> To: internals@lists.php.net
> Subject: [PHP-DEV] [RFC] [Vote] Base convert changes
> 
> Hi all
> 
> I have put my RFC base convert changes to vote this morning
> 
> https://wiki.php.net/rfc/base_convert_improvements
> 
> Two votes, one to raise a deprecated error in PHP7.4 (raised to exception in PHP
> 8) when base_convert encounters something it doesnt know how to convert.
> 
> Second vote is to allow negative numbers, eg base_convert('-FF', 16,
> 10) would return -255 (this returns 255 currently)
> 
> Voting ends 3rd July
> 
> Thanks
> 
> Scott
> 
> --
>  To unsubscribe, visit:
> http://www.php.net/unsub.php

---

## #105996 — Scott Dutton — 2019-06-20T11:16:09+00:00

URL: https://externals.io/message/105980#105996

Hi Chu,

Its currently coded to treat that as 'ff' so any odd amount of '-' 
makes it negative, and any even amount is positive.

Thanks

Scott


> Hi Scott,
>
> Could you clarify what will happen if multiple negative sign occurs.
> I didn't find it in the RFC.
> e.g. base_convert('--ff', 16, 10)
>
> Thanks,
> CHU Zhaowei
>
> > […]

---

## #106123 — Scott Dutton — 2019-07-01T14:09:33+00:00

URL: https://externals.io/message/105980#106123

Hi all

I have made a PR for 7.4 for just the ignoring invalid input.  I will 
open a similar one for PHP 8.

https://github.com/php/php-src/pull/4328

All tests have been fixed for linux, there is one failure for windows 
which I am looking in to.

Voting ends in a few days time so last chance to vote. looks like the 
negative number part is not going to pass so the PR has not been 
updated.
Link to RFC if you need it - 
https://wiki.php.net/rfc/base_convert_improvements

Any questions please let me know

Thanks

Scott

---

## #106128 — Nikita Popov — 2019-07-02T16:38:12+00:00

URL: https://externals.io/message/105980#106128

> Hi all
>
> I have made a PR for 7.4 for just the ignoring invalid input.  I will
> open a similar one for PHP 8.
>
> https://github.com/php/php-src/pull/4328
>
> All tests have been fixed for linux, there is one failure for windows
> which I am looking in to.
>
> Voting ends in a few days time so last chance to vote. looks like the
> negative number part is not going to pass so the PR has not been
> updated.
> Link to RFC if you need it -
> https://wiki.php.net/rfc/base_convert_improvements
>
> Any questions please let me know
>
> Thanks
>
> Scott
>

A possibility to consider would to only support negative numbers in bindec,
octdec and hexdec. Allowing negative numbers wouldn't change any existing
behavior (assuming we consider the leading "-" an error before, as we would
per this RFC). The problem is only on the decbin, decoct and dechex side,
where we currently treat the input as unsigned. base_convert could also
support negative numbers, though it might need some implementation changes
(it would be great to make base_convert directly work from string -> string
to avoid the float precision loss.)

Nikita
