phpstorm.dev

PHP ecosystem insights

PHP knowledge

Versioned PHP knowledge with primary sources and explicit verification dates.

Source checks through 2026-10-14 · 56 sources

Verified 2026-10-09 discussion Permanent entry

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

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