Re: [RFC] Throw ValueError for invalid characters in number base functions
| From: | Sjoerd Langkemper | Date: | Mon, 31 Aug 2026 13:36:19 +0000 |
| Subject: | Re: [RFC] Throw ValueError for invalid characters in number base functions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-132399@lists.php.net to get a copy of this message | ||
On Mon, Aug 31, 2026, at 11:05, Tim Düsterhus wrote:
> > This will throw an error for octdec, hexdec, bindec and base_convert on
> > invalid input.
>
> I'm not sure ValueError is the correct throwable to use here: I believe
> passing “user-provided” inputs to these methods might be an expected use
> case, where developers would then be interested in catching the
> resulting exception as an implicit validation mechanism. This is also
> acknowledged by the RFC: ...
>
> The Error hierarchy is not intended to be caught, though. It should thus
> use something from the Exception hierarchy.
I wasn't aware of a distinction between error and exception objects like this. Is this
documented somewhere? Is there a policy when to throw errors and when to throw exceptions? Does the
documentation describe that developers should only catch exceptions and not errors?
Why would these functions be used for user input more often than other functions? How can we
determine whether a function should throw an exception or an error?
I think ValueError is still the right thing to throw.
On Mon, Aug 31, 2026, at 11:05, Tim Düsterhus wrote:
> On 2026-08-28 10:24, Sjoerd Langkemper wrote:
> > Next Friday I'll open the vote for the RFC for Throw ValueError for
> > invalid characters in number base functions.
>
> From what I see this is the first email regarding this RFC
The RFC was announced here: https://news-web.php.net/php.internals/132219
And before that the same idea in another RFC: https://news-web.php.net/php.internals/131448
This gave more than a month to respond to the proposal, and exactly two weaks for responding to the
exact RFC.
Regards,
Sjoerd