Re: [PRE-RFC] PREG_THROW_ON_ERROR flag
| From: | Tim Düsterhus | Date: | Thu, 09 Jul 2026 09:03:24 +0000 |
| Subject: | Re: [PRE-RFC] PREG_THROW_ON_ERROR flag | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131829@lists.php.net to get a copy of this message | ||
Hi
On 2026-07-07 03:17, Osama Aldemeery wrote:
I'd like to propose adding aI personally hate this kind of flag, because of its opt-in nature. But given the precedent and unless and until we rebuild the regex API in a clean and modern way, it makes sense to me as a “stop-gap” solution that should allow to get rid of some custom userland code that wraps pcre into explicit checks.PREG_THROW_ON_ERRORflag to thepreg_*()functions, and gauge interest in that.
Passing it to anyPcre\PcreException would technically be fully in line with the naming and Throwable policy, by including the extension name as the prefix. However the existing PCRE functions usepreg_*()call makes a PCRE error throw aPcre\PcreExceptionthat carries thePREG_*_ERRORcode and thepreg_last_error_msg()text
preg_ as a prefix, it will probably be confusing to have the two different prefixes here. Given that, I would suggest going with an unnamespaced \PregException for now and then only introduce a namespace when actually building a new API to not paint us into a corner already.
The naming policy specifically allows for that:
When adding new symbols to existing extensions it is RECOMMENDED to be consistent with existing symbols, rather than to follow the namespacing guidelines.and
Newly introduced extensions MUST follow the following rules, existing extensions SHOULD follow the rules for newly introduced exceptions, but MAY diverge for consistency with existing symbols.-
2. WhetherI would go with ERROR for the reasons you mentioned there. Best regards Tim Düsterhus*_ON_ERRORreads better than*_ON_FAILUREgiven the existingpreg_last_error()/PREG_*_ERRORvocabulary.