Hi,

>     function is_valid_preg_pattern( $pattern ) {
>         $is_valid = true;
>
>         set_error_handler( function () use ( &$is_valid ) { $is_valid = 
> false; return true; }, E_WARNING );
>         preg_match( $pattern, '' );
>         restore_error_handler();
>
>         return $is_valid;
>     }

Setting and restoring the global error handler to validate a pattern
is exactly what I would qualify as clunky/hacky. Also this requires
internal knowledge on how this works, which feels very wrong for
something like that.

— Alexandre Daubois

Reply via email to