[PHP-DEV] Re: [RFC] [Discussion] PREG_THROW_ON_ERROR
Osama Aldemeery <[email protected]>
| Newsgroups | gmane.comp.php.devel |
|---|---|
| Message-ID | <CABE7Eu_yMr2NHB5PfRWAg8mrYRs-11tABpkWBibAgC0sjJyTSw@mail.gmail.com> |
On Tue, Jul 28, 2026 at 3:56 AM Osama Aldemeery <[email protected]> wrote: > > Hi all, > > Following the earlier pre-RFC discussion (https://news-web.php.net/php.internals/131783), I've written this up as a proper RFC: https://wiki.php.net/rfc/preg_throw_on_error > > Short version: > > a `PREG_THROW_ON_ERROR` flag you pass to any `preg_*()` call, so a PCRE error throws a `\PregException` you can catch > instead of a warning plus a `false` / `null` you have to notice and then chase through `preg_last_error()`. > Same thing `JSON_THROW_ON_ERROR` and `FILTER_THROW_ON_FAILURE` already do for their functions. > It's opt-in, so nothing changes without the flag. > > The flag only changes how an error is delivered. A call does exactly the same thing with it or without it, byte for byte. > The only difference is that at the end, any error the call would have recorded is additionally thrown, carrying the same code and > message `preg_last_error()`/`preg_last_error_msg()` would report. > > For array arguments that means the flag mirrors `preg_last_error()`...it throws whatever error the same call leaves there, > which for `preg_replace()` over an array is the last-processed entry, not the first. (In the pre-RFC I'd floated throwing on the first failing element instead). > Whether the `preg_*()` functions should stop at the first failing entry is a separate question about those functions, one that applies with or without the flag, so it's out of scope here. > > The exception name is settled from the pre-RFC as `\PregException` (thanks Tim) and the flag as `PREG_THROW_ON_ERROR`. > > Target is the next feature release after 8.6 since 8.6's beta1 is too close for this to conclude discussion and a vote in time. > > I also saw Larry's note asking to hold new business that isn't targeting 8.6 until the freeze rush is over. > This won't catch 8.6, so I'm not asking for any priority while the freeze is on. But the pre-RFC discussion was already open before > Larry's note, so I'd rather keep it ticking over quietly than restart it in September. > If someone prefers I park it until then, please say so and I will. > > Implementation and tests: https://github.com/php/php-src/pull/22797 > > Thanks, > Osama Hi all, This has gone quiet, which I'm taking as the freeze crunch and people being busy, not as everyone being fine with it as-is. And it isn't targeting 8.6 anyway, so there's no rush on my side. So I'll park it and bring it back early September just like Larry asked, once the release dust has settled, to give anyone who hasn't weighed in a clear window to do so. The points raised so far (the exception hierarchy, the warning behavior) are addressed in the RFC, so if it's still quiet after I resurface it, the natural next step is to move toward a vote. I'd rather that happen once everyone's had a fair chance than while half the list is heads-down on the release. If there's something you'd want settled before a vote, now or early September both work for me. I'll ping the thread again then. Thanks, Osama