The voting phase for the PREG_THROW_ON_ERROR RFC has begun, announced by author Osama Aldemeery on the PHP internals list after a discussion period without open issues. Voting closes on 2026-09-18 at 17:00 UTC. The RFC lives at wiki.php.net/rfc/preg_throw_on_error, and the implementation is in php-src pull request 22797.
The proposal adds an opt-in PREG_THROW_ON_ERROR flag. Passing it to any preg_* matching function makes every PCRE error recorded by the call additionally throw a \PregException. The exception's code and message match preg_last_error() and preg_last_error_msg() exactly. Calls without the flag behave exactly as they do today.
Tim Düsterhus voted against the RFC while agreeing with the general concept. He objects to keeping a Warning on compilation errors: since the feature is new and opt-in, he argues there are no backwards compatibility constraints, and the requirement that $e->getMessage() equal preg_last_error_msg() weakens the feature because the exception should carry all necessary information.
He also disagrees with leaving exceptions thrown inside user callbacks unwrapped. In his view they should become a \PregException with the original exception set as $previous. Otherwise developers still need a catch(Exception) around every preg_ call, which undermines the point of a dedicated exception class. He notes this also conflicts with the PHP throwable policy, which requires extensions to wrap exceptions from external functionality and set $previous.




Comments
No comments yet — be the first.
Open the discussion
No account or password needed — just enter your e-mail and we’ll send you a one-time sign-in link. First time here? You’re set up automatically.
Your rating will be applied automatically after you sign in.
Check your inbox
We’ve sent a sign-in link to …. Open it on this device — this tab will sign you in automatically.
Nothing arrived? Check your spam folder — and mark the mail as "Not spam" so it lands in your inbox next time.