# base_convert should throw a ValueError on characters not valid in number base

- Thread: https://externals.io/message/131448
- Original archive: https://news-web.php.net/php.internals/131448
- Started by Sjoerd Langkemper on 2026-06-22T09:21:33+00:00
- Messages: 2
- RFC: Base Convert improvements (Implemented (PHP 7.4)) — https://externals.io/rfc/base_convert_improvements.md
- RFC: Grouped ValueError Conversions (Inactive) — https://externals.io/rfc/php86_valueerror_conversions.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

---

## #131448 — Sjoerd Langkemper — 2026-06-22T09:21:33+00:00

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

Hello,

Functions that convert from one number base to another should only accept characters valid in that number base. E.g. only 0-9, a-f are allowed for hexadecimal, so what should hexdec('z') do?

In the past, such characters were silently ignored. Since PHP 7.4 a deprecation notice would be generated, as a result of this RFC: https://wiki.php.net/rfc/base_convert_improvements. That RFC also proposed throwing an exception as of PHP 8.0, but that was never implemented. I propose to throw a ValueError for invalid characters starting in PHP 8.6. I added this to the Grouped ValueError Conversions for PHP 8.6 RFC: https://wiki.php.net/rfc/php86_valueerror_conversions#throw_error_for_invalid_characters_for_number_base

This applies to bindec, octdec, hexdec, and base_convert.

Regards,

Sjoerd Langkemper

---

## #132219 — Sjoerd Langkemper — 2026-08-14T10:13:26+00:00

URL: https://externals.io/message/131448#132219 · In reply to: #131448

> I propose to throw a ValueError for invalid characters ... This applies to bindec, octdec, hexdec, and base_convert.

I created a new RFC for this: https://wiki.php.net/rfc/throw_error_for_invalid_characters_for_number_base

It was originally in the "Grouped ValueError Conversions for PHP 8.6" RFC, but that wasn't voted on in time.

Regards,

Sjoerd
