PHP has four functions that convert a number string from one base to another: bindec(), octdec(), hexdec() and base_convert(). Today they silently skip any character that doesn't belong in that base. This RFC from Sjoerd Langkemper would make them throw an Exception instead, starting in PHP 8.7.
Why change it
Skipping bad characters hides mistakes. z isn't a hex digit, for example, so hexdec('z') ignores it and gives you 0.
PHP 7.4 started emitting a deprecation for this, as part of the Base Convert Improvements RFC. The plan back then was to throw an error in PHP 8. The deprecation shipped but the error never did, and this RFC finishes that job.
Show me
var_dump(hexdec('z')); // PHP 7.4 - 8.6: // Deprecated: Invalid characters passed for attempted conversion, these have been ignored in ... // int(0) // PHP 8.7 (proposed): // Fatal error: Uncaught Exception: Invalid characters passed for attempted conversion in ...
With base_convert(), what counts as invalid depends on the base you pass in:
base_convert('f', 16, 10); // 'f' is fine in base 16 base_convert('f', 15, 10); // throws an Exception
Why Exception and not ValueError
The first version of the RFC used ValueError, and the author switched to Exception in version 0.3. A ValueError suggests a bug in your program, but bad input here isn't always a bug, since it can come straight from users. A plain Exception fits that case better.
What it means for existing code
Code that relies on invalid characters being skipped will now get an Exception. If your input comes from users, wrap these calls in try/catch.
The author expects the most common case to be separators, like hexdec('1234-5678'), which already triggers a deprecation today. You can strip the separators out first with ordinary string functions.
Related functions like base64_decode() and intval() aren't affected.
Where it stands
The RFC is under discussion on the internals mailing list, and no vote has started yet. It targets PHP 8.7 and would need a two-thirds majority to pass.