The Daily Commit · Section Edition Front Page PHP AI Dev EN DE FR ES

The Php Times

RFC Watch — Ecosystem

Vote Opens on PREG_THROW_ON_ERROR Flag for preg_* Functions


Voting has started on a PHP RFC that adds an opt-in PREG_THROW_ON_ERROR flag for preg_* functions.

PHP INTERNALS ([RFC]/[VOTE]), September 4, 2026 curated by Georg

With the flag, PCRE errors surface as a \PregException instead of requiring preg_last_error() checks. The vote closes on 2026-09-18, with Tim Düsterhus among the early opponents.

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.

Read the original source ↗

Rate this article: 0

Readers’ Forum

No contributions yet — open the debate.

← Ecosystem — Page B1

"All the Code That's Fit to Ship" · The Daily Commit · Screen edition · Imprint · Privacy Policy