Exception for invalid characters in number base functions
Under discussion; not accepted. The RFC page (version 0.3, dated 2026-08-11, last modified 2026-10-09 at 10:29 UTC) and the official RFC index both list it as under discussion. The proposed version is PHP 8.7, and acceptance needs a 2/3 majority. On 9 October the author announced that the vote will open on Friday 16 October. The voting thread reads "tbd", so no vote is open yet.
Proposal
bindec(), octdec(), hexdec() and base_convert() would throw when the input contains a
character that is not valid in the given base. Today they ignore such characters and emit
E_DEPRECATED ("Invalid characters passed for attempted conversion, these have been ignored"),
so hexdec('z') returns int(0). For base_convert() validity depends on the source base:
'f' is accepted in base 16 but would throw in base 15.
Version 0.3 changed the exception from ValueError to a plain Exception. The page argues that
ValueError implies a bug in the program, which bad input is not necessarily. More specific
exceptions are listed as rejected for now: the SPL exceptions belong to another extension, and
ext/standard has no suitable exception of its own. Both the official index and the internals
thread still use the older "Throw ValueError" title.
Background and affected versions
The Base Convert Improvements RFC,
implemented in PHP 7.4, added the deprecation notice and named an exception in a later version as
the next step. That step never happened. Since PHP 7.4 invalid characters are ignored with a
deprecation notice; the RFC's example lists this behavior for PHP 7.4 through 8.6. The RFC expects separator
characters such as hexdec('1234-5678') to be the main legitimate use broken by the change.
base64_decode(), intval() and other functions are out of scope.
Evidence and limitations
- The implementation is php-src PR #22365, opened on
19 June 2026. GitHub labels it "ABI break". Its description says it changes the behavior to an
Exception, but its first commit message still saysValueError. Whether it is merged or matches version 0.3 was not checked. - An earlier internals message (132379) also said a vote would open the following Friday, and called the RFC "not really controversial". The fetched text has no date. No vote followed it: the page still reads "Voting thread: tbd" and the RFC is still under discussion.
- The page's vote block shows "Final result: 0 0 0" and "This poll has been closed". This is the unopened widget, not a ballot result.
Related: Filter enums, another PHP 8.7 proposal about handling invalid input.