3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = "I like cats."; $needles = ['cat' => 0, 'dog' => 1]; function regex(string $haystack, array $needles) { $regex = implode('|', array_map('preg_quote', array_keys($needles))); if (!preg_match("#$regex#", $haystack, $m)) { throw new Exception('No needles were found in the haystack'); } return $needles[$m[0]]; } try { var_export(regex($haystack, $needles)); } catch (Exception $e) { echo $e->getMessage(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 10
Branch analysis from position: 10
2 jumps found. (Code = 107) Position 1 = 11, Position 2 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XPW1U
function name:  (null)
number of ops:  15
compiled vars:  !0 = $haystack, !1 = $needles, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'I+like+cats.'
    4     1        ASSIGN                                                   !1, <array>
   14     2        INIT_FCALL                                               'var_export'
          3        INIT_FCALL                                               'regex'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $5      
          7        SEND_VAR                                                 $5
          8        DO_ICALL                                                 
          9      > JMP                                                      ->14
   15    10  E > > CATCH                                       last         'Exception'
   16    11    >   INIT_METHOD_CALL                                         !2, 'getMessage'
         12        DO_FCALL                                      0  $7      
         13        ECHO                                                     $7
   17    14    > > RETURN                                                   1

Function regex:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XPW1U
function name:  regex
number of ops:  32
compiled vars:  !0 = $haystack, !1 = $needles, !2 = $regex, !3 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        INIT_FCALL                                               'implode'
          3        SEND_VAL                                                 '%7C'
          4        INIT_FCALL                                               'array_map'
          5        SEND_VAL                                                 'preg_quote'
          6        INIT_FCALL                                               'array_keys'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $4      
          9        SEND_VAR                                                 $4
         10        DO_ICALL                                         $5      
         11        SEND_VAR                                                 $5
         12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !2, $6
    8    14        INIT_FCALL                                               'preg_match'
         15        ROPE_INIT                                     3  ~9      '%23'
         16        ROPE_ADD                                      1  ~9      ~9, !2
         17        ROPE_END                                      2  ~8      ~9, '%23'
         18        SEND_VAL                                                 ~8
         19        SEND_VAR                                                 !0
         20        SEND_REF                                                 !3
         21        DO_ICALL                                         $11     
         22        BOOL_NOT                                         ~12     $11
         23      > JMPZ                                                     ~12, ->28
    9    24    >   NEW                                              $13     'Exception'
         25        SEND_VAL_EX                                              'No+needles+were+found+in+the+haystack'
         26        DO_FCALL                                      0          
         27      > THROW                                         0          $13
   11    28    >   FETCH_DIM_R                                      ~15     !3, 0
         29        FETCH_DIM_R                                      ~16     !1, ~15
         30      > RETURN                                                   ~16
   12    31*     > RETURN                                                   null

End of function regex

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
129.61 ms | 1407 KiB | 24 Q