3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sed(string $re, string $sub): string { if (mb_strlen($re, "8bit") < 4 || $re[0] !== "s") throw new Error("Your syntax is invalid, go drown yourself"); [1 => $re, 2 => $rep, 3 => $mod] = preg_split("|(?<!\\\\){$re[1]}|", $re); $re = str_replace('@', '\@', $re); return preg_replace("@$re@$mod", $rep, $sub); } echo sed('s/Cat/Fox/i', 'Cat makes dog play guitar.'), PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o9Hiq
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'sed'
          1        SEND_VAL                                                 's%2FCat%2FFox%2Fi'
          2        SEND_VAL                                                 'Cat+makes+dog+play+guitar.'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5        ECHO                                                     '%0A'
          6      > RETURN                                                   1

Function sed:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/o9Hiq
function name:  sed
number of ops:  50
compiled vars:  !0 = $re, !1 = $sub, !2 = $rep, !3 = $mod
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'mb_strlen'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '8bit'
          5        DO_ICALL                                         $4      
          6        IS_SMALLER                                       ~5      $4, 4
          7      > JMPNZ_EX                                         ~5      ~5, ->11
          8    >   FETCH_DIM_R                                      ~6      !0, 0
          9        IS_NOT_IDENTICAL                                 ~7      ~6, 's'
         10        BOOL                                             ~5      ~7
         11    > > JMPZ                                                     ~5, ->16
    6    12    >   NEW                                              $8      'Error'
         13        SEND_VAL_EX                                              'Your+syntax+is+invalid%2C+go+drown+yourself'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $8
    8    16    >   INIT_FCALL                                               'preg_split'
         17        ROPE_INIT                                     3  ~12     '%7C%28%3F%3C%21%5C%5C%29'
         18        FETCH_DIM_R                                      ~10     !0, 1
         19        ROPE_ADD                                      1  ~12     ~12, ~10
         20        ROPE_END                                      2  ~11     ~12, '%7C'
         21        SEND_VAL                                                 ~11
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $14     
         24        FETCH_LIST_R                                     $15     $14, 1
         25        ASSIGN                                                   !0, $15
         26        FETCH_LIST_R                                     $17     $14, 2
         27        ASSIGN                                                   !2, $17
         28        FETCH_LIST_R                                     $19     $14, 3
         29        ASSIGN                                                   !3, $19
         30        FREE                                                     $14
   10    31        INIT_FCALL                                               'str_replace'
         32        SEND_VAL                                                 '%40'
         33        SEND_VAL                                                 '%5C%40'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $21     
         36        ASSIGN                                                   !0, $21
   12    37        INIT_FCALL                                               'preg_replace'
         38        ROPE_INIT                                     4  ~24     '%40'
         39        ROPE_ADD                                      1  ~24     ~24, !0
         40        ROPE_ADD                                      2  ~24     ~24, '%40'
         41        ROPE_END                                      3  ~23     ~24, !3
         42        SEND_VAL                                                 ~23
         43        SEND_VAR                                                 !2
         44        SEND_VAR                                                 !1
         45        DO_ICALL                                         $26     
         46        VERIFY_RETURN_TYPE                                       $26
         47      > RETURN                                                   $26
   13    48*       VERIFY_RETURN_TYPE                                       
         49*     > RETURN                                                   null

End of function sed

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.43 ms | 1403 KiB | 22 Q