phpstorm.dev

PHP ecosystem insights

PHP knowledge

Versioned PHP knowledge with primary sources and explicit verification dates.

Source checks through 2026-10-27 · 57 sources · This published snapshot is over 48 hours old.

Verified 2026-10-25 voting Permanent entry

Exception for invalid characters in number base functions

Voting; not accepted. The vote opened on 16 October 2026. The author's voting thread went out at about 07:41 UTC, and the RFC page (version 0.3, dated 2026-08-11, last modified 2026-10-16 at 08:13 UTC) changed its status to Voting. The official RFC index also lists it as voting. There is one question: "Throw a Exception for invalid characters in number base conversion functions?" It is the primary vote, needs a 2/3 majority and closes on 2026-11-01 at 15:30 UTC. When the page was read at about 10:05 UTC on 16 October, the interim count was 3 yes, 0 no, 0 abstain. This is an interim count, not a result. On 21 October at about 16:05 UTC the page listed 22 voters with an interim count of 21 yes, 1 no, 0 abstain, still not a result. On 22 October at about 10:05 UTC (page still last modified 2026-10-16 08:13 UTC) it listed 23 voters with an interim count of 22 yes, 1 no, 0 abstain, again not a result. On 23 October at about 22:05 UTC (page still last modified 2026-10-16 08:13 UTC) the interim count was 23 yes, 1 no, 0 abstain (24 voters), still not a result. On 25 October at about 17:05 UTC (page still last modified 2026-10-16 08:13 UTC) it was 24 yes, 1 no, 0 abstain (25 voters), again not a result. It was unchanged at about 05:05 UTC on 27 October. The proposed version is PHP 8.7. The vote opened on the date the author announced on 9 October.

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. The voting thread uses the new "Throw exception" title. Until 22 October the official index still used the older "Throw ValueError" title. The index collected at 10:01 UTC on 22 October uses "Throw exception for invalid characters in number base functions", matching the page.

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

Objection to the plain Exception (21 October)

On 21 October a voter replied in the voting thread that they had voted no solely because of the generic \Exception, which callers can only catch together with every other exception. They pointed out that the Base Convert Improvements RFC had named InvalidArgumentException as the intended PHP 8 step, and asked for the SPL restriction to be resolved or a dedicated exception class introduced. The author answered that a more specific exception is desirable but not easy to get right now, that throwing Exception now makes it possible to change to something more specific later, and that InvalidArgumentException is wrong because it signals a type error and extends LogicException (a programming error), whereas bad input need not be one. news-web.php.net returned HTTP 502 for the individual messages, so they were read on the externals.io mirror.

Related: Filter enums, another PHP 8.7 proposal about handling invalid input.