3v4l.org

run code in 500+ PHP versions simultaneously
<?php /** * Return an error message if the given pattern argument or its underlying regular expression * are not syntactically valid. Otherwise (if they are valid), NULL is returned. * * @param $pattern * * @return string|null */ function regexHasErrors($pattern): ?string { if(@preg_match($pattern, '') === false){ return str_replace("preg_match(): ", "", error_get_last()["message"]); //Make it prettier by removing the function name prefix } return NULL; } $pattern = "/incorrect)/"; if($error = regexHasErrors($pattern)){ echo $error; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/EHtVV
function name:  (null)
number of ops:  8
compiled vars:  !0 = $pattern, !1 = $error
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                       !0, '%2Fincorrect%29%2F'
   21     1        INIT_FCALL                                                   'regexhaserrors'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $3      
          4        ASSIGN                                               ~4      !1, $3
          5      > JMPZ                                                         ~4, ->7
   22     6    >   ECHO                                                         !1
   23     7    > > RETURN                                                       1

Function regexhaserrors:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EHtVV
function name:  regexHasErrors
number of ops:  16
compiled vars:  !0 = $pattern
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
   12     1        BEGIN_SILENCE                                        ~1      
          2        FRAMELESS_ICALL_2                preg_match          ~2      !0, ''
          3        END_SILENCE                                                  ~1
          4        TYPE_CHECK                                        4          ~2
          5      > JMPZ                                                         ~3, ->13
   13     6    >   INIT_FCALL                                                   'error_get_last'
          7        DO_ICALL                                             $4      
          8        FETCH_DIM_R                                          ~5      $4, 'message'
          9        FRAMELESS_ICALL_3                str_replace         ~6      'preg_match%28%29%3A+', ''
         10        OP_DATA                                                      ~5
         11        VERIFY_RETURN_TYPE                                           ~6
         12      > RETURN                                                       ~6
   16    13    > > RETURN                                                       null
   17    14*       VERIFY_RETURN_TYPE                                           
         15*     > RETURN                                                       null

End of function regexhaserrors

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.37 ms | 2151 KiB | 19 Q