3v4l.org

run code in 300+ PHP versions simultaneously
<?php function routedispatch_preg($path, $patterns) { foreach ($patterns as $pattern) { if (preg_match($pattern[0], $path)) { return $pattern[1](); } } } function foo() { var_dump('foo dispatched.'); } function bar() { var_dump('bar dispatched.'); } $path = '/news/123'; $patterns = [ 'news' => ['#^/news/?$#', 'foo'], 'newsid' => ['#^/news/(\d+)$#', 'bar'] ]; routedispatch_preg($path, $patterns);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/08gNQ
function name:  (null)
number of ops:  7
compiled vars:  !0 = $path, !1 = $patterns
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, '%2Fnews%2F123'
   25     1        ASSIGN                                                   !1, <array>
   33     2        INIT_FCALL                                               'routedispatch_preg'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Function routedispatch_preg:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/08gNQ
function name:  routedispatch_preg
number of ops:  18
compiled vars:  !0 = $path, !1 = $patterns, !2 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2      > FE_RESET_R                                       $3      !1, ->16
          3    > > FE_FETCH_R                                               $3, !2, ->16
    7     4    >   INIT_FCALL                                               'preg_match'
          5        FETCH_DIM_R                                      ~4      !2, 0
          6        SEND_VAL                                                 ~4
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9      > JMPZ                                                     $5, ->15
    9    10    >   FETCH_DIM_R                                      ~6      !2, 1
         11        INIT_DYNAMIC_CALL                                        ~6
         12        DO_FCALL                                      0  $7      
         13        FE_FREE                                                  $3
         14      > RETURN                                                   $7
    5    15    > > JMP                                                      ->3
         16    >   FE_FREE                                                  $3
   15    17      > RETURN                                                   null

End of function routedispatch_preg

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/08gNQ
function name:  foo
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'foo+dispatched.'
          2        DO_ICALL                                                 
          3      > RETURN                                                   null

End of function foo

Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/08gNQ
function name:  bar
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'bar+dispatched.'
          2        DO_ICALL                                                 
          3      > RETURN                                                   null

End of function bar

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.95 ms | 1403 KiB | 18 Q