3v4l.org

run code in 300+ PHP versions simultaneously
<?php $mf = function () { /** * Used to store functions and allow recursive callbacks. * @var null|callback */ static $deploy = null; /** * Defined matches. * @var array */ static $ms = array(); /** * Dependency Injection callbacks, used for settings too. * @var array */ static $di = array(); // used to shorten code $num_args = func_num_args(); $get_args = func_get_args(); // used to retrieve currently defined matches // http://www.php.net/manual/en/regexp.reference.conditional.php // http://stackoverflow.com/questions/14598972/catch-all-regular-expression if ($num_args === 0 && PHP_SAPI !== 'cli') { return '/?(?!(' . implode('|', $ms) . ')$).*'; } elseif ($num_args === 2 && preg_match('#^[^/].+#', $get_args[0])) { // functions used for Dependency Injection and settings return $di[$get_args[0]] = $get_args[1]; } elseif ($num_args === 1 && preg_match('#^[^/].+#', $get_args[0])) { return is_callable($di[$get_args[0]]) ? call_user_func($di[$get_args[0]]) : $di[$get_args[0]]; } // functions have to be stored only once if (is_null($deploy) && PHP_SAPI === 'cli') { /** * Command line interface for the main function. * * @link http://php.net/manual/en/language.types.float.php * * @param callback $callback Function invoked when script ends * @param integer $priority Set `$callback` priority from 0 (high) to ~1.8e308 (low) * @return void */ $deploy = function ($callback, $priority = 0) use (&$deploy) { /** * Checking well formed call */ assert(is_callable($callback)); assert(is_numeric($priority)); /** * Arguments passed to the script. * @link http://php.net/manual/en/reserved.variables.argv.php * @var array */ $argv = $GLOBALS['argv']; if ($priority > 0) { /** * Recursion is used to set callback priority */ register_shutdown_function($deploy, $callback, $priority - 1); } else { $argv[0] = $callback; /** * register_shutdown_function is used to call added functions when script ends * @link http://it2.php.net/manual/en/function.register-shutdown-function.php */ call_user_func_array('register_shutdown_function', $argv); } }; } elseif (is_null($deploy)) { /** * Function used as a router. * * @link http://php.net/manual/en/language.types.float.php * * @param string $regex Regular expression used to match requested URL * @param callback $callback Function invoked when there's a match * @param string $method Request method(s) * @param float $priority Set `$callback` priority from 0 (high) to ~1.8e308 (low) * @return void */ $deploy = function ($regex, $callback, $method = 'GET', $priority = 0) use (&$deploy, &$ms) { /** * Checking well formed call */ assert(is_string($regex)); assert(is_callable($callback)); assert(is_string($method)); assert(is_numeric($priority)); // match stored as unique $ms[md5($regex)] = $regex; if ($priority > 0) { /** * Recursion is used to set callback priority */ register_shutdown_function($deploy, $regex, $callback, $method, $priority - 1); } elseif (preg_match('#' . $method . '#', $_SERVER['REQUEST_METHOD'])) { if (preg_match('#^' . $regex . '$#', $_SERVER['REQUEST_URI'], $matches)) { /** * Named subpatterns aren't allowed * @link http://it2.php.net/manual/en/regexp.reference.subpatterns.php */ while (list($key) = each($matches)) { if (!is_int($key)) { unset($matches[$key]); } } /** * Closure is added to `register_shutdown_function` calling */ if (isset($matches[0]) && $matches[0] === $_SERVER['REQUEST_URI']) { $matches[0] = $callback; } else { array_unshift($matches, $callback); } /** * register_shutdown_function is used to call added functions when script ends * @link http://it2.php.net/manual/en/function.register-shutdown-function.php */ call_user_func_array('register_shutdown_function', $matches); } } }; } return call_user_func_array($deploy, func_get_args()); }; assert_options(ASSERT_ACTIVE, 1); assert_options(ASSERT_BAIL, 1); $mf('/.*', function () { echo "Hello "; }); $mf('/.*', function () { echo "World!"; });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TYQMm
function name:  (null)
number of ops:  21
compiled vars:  !0 = $mf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTYQMm%3A2%240'
          1        ASSIGN                                                   !0, ~1
  137     2        INIT_FCALL                                               'assert_options'
          3        SEND_VAL                                                 1
          4        SEND_VAL                                                 1
          5        DO_ICALL                                                 
  138     6        INIT_FCALL                                               'assert_options'
          7        SEND_VAL                                                 3
          8        SEND_VAL                                                 1
          9        DO_ICALL                                                 
  140    10        INIT_DYNAMIC_CALL                                        !0
         11        SEND_VAL_EX                                              '%2F.%2A'
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTYQMm%3A140%243'
  142    13        SEND_VAL_EX                                              ~5
         14        DO_FCALL                                      0          
  143    15        INIT_DYNAMIC_CALL                                        !0
         16        SEND_VAL_EX                                              '%2F.%2A'
         17        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTYQMm%3A143%244'
  145    18        SEND_VAL_EX                                              ~7
         19        DO_FCALL                                      0          
         20      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FTYQMm%3A2%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 36, Position 2 = 42
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 59
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 55
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
2 jumps found. (Code = 46) Position 1 = 61, Position 2 = 62
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 73
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
Branch analysis from position: 62
Branch analysis from position: 42
Branch analysis from position: 27
Branch analysis from position: 10
filename:       /in/TYQMm
function name:  {closure}
number of ops:  80
compiled vars:  !0 = $deploy, !1 = $ms, !2 = $di, !3 = $num_args, !4 = $get_args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   BIND_STATIC                                              !0
   12     1        BIND_STATIC                                              !1
   17     2        BIND_STATIC                                              !2
   20     3        FUNC_NUM_ARGS                                    ~5      
          4        ASSIGN                                                   !3, ~5
   21     5        FUNC_GET_ARGS                                    ~7      
          6        ASSIGN                                                   !4, ~7
   26     7        IS_IDENTICAL                                     ~9      !3, 0
          8      > JMPZ_EX                                          ~9      ~9, ->10
          9    >   BOOL                                             ~9      <false>
         10    > > JMPZ                                                     ~9, ->19
   27    11    >   INIT_FCALL                                               'implode'
         12        SEND_VAL                                                 '%7C'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $10     
         15        CONCAT                                           ~11     '%2F%3F%28%3F%21%28', $10
         16        CONCAT                                           ~12     ~11, '%29%24%29.%2A'
         17      > RETURN                                                   ~12
         18*       JMP                                                      ->59
   28    19    >   IS_IDENTICAL                                     ~13     !3, 2
         20      > JMPZ_EX                                          ~13     ~13, ->27
         21    >   INIT_FCALL                                               'preg_match'
         22        SEND_VAL                                                 '%23%5E%5B%5E%2F%5D.%2B%23'
         23        FETCH_DIM_R                                      ~14     !4, 0
         24        SEND_VAL                                                 ~14
         25        DO_ICALL                                         $15     
         26        BOOL                                             ~13     $15
         27    > > JMPZ                                                     ~13, ->34
   30    28    >   FETCH_DIM_R                                      ~16     !4, 0
         29        FETCH_DIM_R                                      ~18     !4, 1
         30        ASSIGN_DIM                                       ~17     !2, ~16
         31        OP_DATA                                                  ~18
         32      > RETURN                                                   ~17
         33*       JMP                                                      ->59
   31    34    >   IS_IDENTICAL                                     ~19     !3, 1
         35      > JMPZ_EX                                          ~19     ~19, ->42
         36    >   INIT_FCALL                                               'preg_match'
         37        SEND_VAL                                                 '%23%5E%5B%5E%2F%5D.%2B%23'
         38        FETCH_DIM_R                                      ~20     !4, 0
         39        SEND_VAL                                                 ~20
         40        DO_ICALL                                         $21     
         41        BOOL                                             ~19     $21
         42    > > JMPZ                                                     ~19, ->59
   32    43    >   INIT_FCALL                                               'is_callable'
         44        FETCH_DIM_R                                      ~22     !4, 0
         45        FETCH_DIM_R                                      ~23     !2, ~22
         46        SEND_VAL                                                 ~23
         47        DO_ICALL                                         $24     
         48      > JMPZ                                                     $24, ->55
   33    49    >   FETCH_DIM_R                                      ~25     !4, 0
         50        FETCH_DIM_R                                      ~26     !2, ~25
         51        INIT_USER_CALL                                0          'call_user_func', ~26
         52        DO_FCALL                                      0  $27     
         53        QM_ASSIGN                                        ~28     $27
         54      > JMP                                                      ->58
   34    55    >   FETCH_DIM_R                                      ~29     !4, 0
         56        FETCH_DIM_R                                      ~30     !2, ~29
         57        QM_ASSIGN                                        ~28     ~30
         58    > > RETURN                                                   ~28
   38    59    >   TYPE_CHECK                                    2  ~31     !0
         60      > JMPZ_EX                                          ~31     ~31, ->62
         61    >   BOOL                                             ~31     <true>
         62    > > JMPZ                                                     ~31, ->67
   48    63    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTYQMm%3A48%241'
         64        BIND_LEXICAL                                             ~32, !0
         65        ASSIGN                                                   !0, ~32
         66      > JMP                                                      ->73
   76    67    >   TYPE_CHECK                                    2          !0
         68      > JMPZ                                                     ~34, ->73
   88    69    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTYQMm%3A88%242'
         70        BIND_LEXICAL                                             ~35, !0
         71        BIND_LEXICAL                                             ~35, !1
         72        ASSIGN                                                   !0, ~35
  134    73    >   INIT_USER_CALL                                0          'call_user_func_array', !0
         74        FUNC_GET_ARGS                                    ~37     
         75        SEND_ARRAY                                               ~37
         76        CHECK_UNDEF_ARGS                                         
         77        DO_FCALL                                      0  $38     
         78      > RETURN                                                   $38
  135    79*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTYQMm%3A2%240

Function %00%7Bclosure%7D%2Fin%2FTYQMm%3A48%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TYQMm
function name:  {closure}
number of ops:  38
compiled vars:  !0 = $callback, !1 = $priority, !2 = $deploy, !3 = $argv
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        BIND_STATIC                                              !2
   52     3        ASSERT_CHECK                                             
          4        INIT_FCALL                                               'assert'
          5        INIT_FCALL                                               'is_callable'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        SEND_VAL                                                 'assert%28is_callable%28%24callback%29%29'
         10        DO_ICALL                                                 
   53    11        ASSERT_CHECK                                             
         12        INIT_FCALL                                               'assert'
         13        INIT_FCALL                                               'is_numeric'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $6      
         16        SEND_VAR                                                 $6
         17        SEND_VAL                                                 'assert%28is_numeric%28%24priority%29%29'
         18        DO_ICALL                                                 
   60    19        FETCH_R                      global              ~8      'GLOBALS'
         20        FETCH_DIM_R                                      ~9      ~8, 'argv'
         21        ASSIGN                                                   !3, ~9
   62    22        IS_SMALLER                                               0, !1
         23      > JMPZ                                                     ~11, ->31
   66    24    >   INIT_FCALL                                               'register_shutdown_function'
         25        SEND_VAR                                                 !2
         26        SEND_VAR                                                 !0
         27        SUB                                              ~12     !1, 1
         28        SEND_VAL                                                 ~12
         29        DO_ICALL                                                 
         30      > JMP                                                      ->37
   68    31    >   ASSIGN_DIM                                               !3, 0
         32        OP_DATA                                                  !0
   73    33        INIT_FCALL                                               'register_shutdown_function'
         34        SEND_ARRAY                                               !3
         35        CHECK_UNDEF_ARGS                                         
         36        DO_FCALL                                      0          
   75    37    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTYQMm%3A48%241

Function %00%7Bclosure%7D%2Fin%2FTYQMm%3A88%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 50
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 99
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 99
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 70
Branch analysis from position: 80
2 jumps found. (Code = 46) Position 1 = 82, Position 2 = 87
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 91
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 95
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 91
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 87
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 74
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 70
Branch analysis from position: 80
Branch analysis from position: 70
Branch analysis from position: 74
Branch analysis from position: 99
Branch analysis from position: 99
filename:       /in/TYQMm
function name:  {closure}
number of ops:  100
compiled vars:  !0 = $regex, !1 = $callback, !2 = $method, !3 = $priority, !4 = $deploy, !5 = $ms, !6 = $matches, !7 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'GET'
          3        RECV_INIT                                        !3      0
          4        BIND_STATIC                                              !4
          5        BIND_STATIC                                              !5
   92     6        ASSERT_CHECK                                             
          7        INIT_FCALL                                               'assert'
          8        TYPE_CHECK                                   64  ~8      !0
          9        SEND_VAL                                                 ~8
         10        SEND_VAL                                                 'assert%28is_string%28%24regex%29%29'
         11        DO_ICALL                                                 
   93    12        ASSERT_CHECK                                             
         13        INIT_FCALL                                               'assert'
         14        INIT_FCALL                                               'is_callable'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $10     
         17        SEND_VAR                                                 $10
         18        SEND_VAL                                                 'assert%28is_callable%28%24callback%29%29'
         19        DO_ICALL                                                 
   94    20        ASSERT_CHECK                                             
         21        INIT_FCALL                                               'assert'
         22        TYPE_CHECK                                   64  ~12     !2
         23        SEND_VAL                                                 ~12
         24        SEND_VAL                                                 'assert%28is_string%28%24method%29%29'
         25        DO_ICALL                                                 
   95    26        ASSERT_CHECK                                             
         27        INIT_FCALL                                               'assert'
         28        INIT_FCALL                                               'is_numeric'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $14     
         31        SEND_VAR                                                 $14
         32        SEND_VAL                                                 'assert%28is_numeric%28%24priority%29%29'
         33        DO_ICALL                                                 
   98    34        INIT_FCALL                                               'md5'
         35        SEND_VAR                                                 !0
         36        DO_ICALL                                         $16     
         37        ASSIGN_DIM                                               !5, $16
         38        OP_DATA                                                  !0
  100    39        IS_SMALLER                                               0, !3
         40      > JMPZ                                                     ~18, ->50
  104    41    >   INIT_FCALL                                               'register_shutdown_function'
         42        SEND_VAR                                                 !4
         43        SEND_VAR                                                 !0
         44        SEND_VAR                                                 !1
         45        SEND_VAR                                                 !2
         46        SUB                                              ~19     !3, 1
         47        SEND_VAL                                                 ~19
         48        DO_ICALL                                                 
         49      > JMP                                                      ->99
  105    50    >   INIT_FCALL                                               'preg_match'
         51        CONCAT                                           ~21     '%23', !2
         52        CONCAT                                           ~22     ~21, '%23'
         53        SEND_VAL                                                 ~22
         54        FETCH_R                      global              ~23     '_SERVER'
         55        FETCH_DIM_R                                      ~24     ~23, 'REQUEST_METHOD'
         56        SEND_VAL                                                 ~24
         57        DO_ICALL                                         $25     
         58      > JMPZ                                                     $25, ->99
  106    59    >   INIT_FCALL                                               'preg_match'
         60        CONCAT                                           ~26     '%23%5E', !0
         61        CONCAT                                           ~27     ~26, '%24%23'
         62        SEND_VAL                                                 ~27
         63        FETCH_R                      global              ~28     '_SERVER'
         64        FETCH_DIM_R                                      ~29     ~28, 'REQUEST_URI'
         65        SEND_VAL                                                 ~29
         66        SEND_REF                                                 !6
         67        DO_ICALL                                         $30     
         68      > JMPZ                                                     $30, ->99
  111    69    > > JMP                                                      ->74
  112    70    >   TYPE_CHECK                                   16  ~31     !7
         71        BOOL_NOT                                         ~32     ~31
         72      > JMPZ                                                     ~32, ->74
  113    73    >   UNSET_DIM                                                !6, !7
  111    74    >   INIT_FCALL_BY_NAME                                       'each'
         75        SEND_VAR_EX                                              !6
         76        DO_FCALL                                      0  $33     
         77        FETCH_LIST_R                                     $34     $33, 0
         78        ASSIGN                                                   !7, $34
         79      > JMPNZ                                                    $33, ->70
  119    80    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~36     !6, 0
         81      > JMPZ_EX                                          ~36     ~36, ->87
         82    >   FETCH_DIM_R                                      ~37     !6, 0
         83        FETCH_R                      global              ~38     '_SERVER'
         84        FETCH_DIM_R                                      ~39     ~38, 'REQUEST_URI'
         85        IS_IDENTICAL                                     ~40     ~37, ~39
         86        BOOL                                             ~36     ~40
         87    > > JMPZ                                                     ~36, ->91
  120    88    >   ASSIGN_DIM                                               !6, 0
         89        OP_DATA                                                  !1
         90      > JMP                                                      ->95
  122    91    >   INIT_FCALL                                               'array_unshift'
         92        SEND_REF                                                 !6
         93        SEND_VAR                                                 !1
         94        DO_ICALL                                                 
  128    95    >   INIT_FCALL                                               'register_shutdown_function'
         96        SEND_ARRAY                                               !6
         97        CHECK_UNDEF_ARGS                                         
         98        DO_FCALL                                      0          
  131    99    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTYQMm%3A88%242

Function %00%7Bclosure%7D%2Fin%2FTYQMm%3A140%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TYQMm
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  141     0  E >   ECHO                                                     'Hello+'
  142     1      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTYQMm%3A140%243

Function %00%7Bclosure%7D%2Fin%2FTYQMm%3A143%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TYQMm
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  144     0  E >   ECHO                                                     'World%21'
  145     1      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTYQMm%3A143%244

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.9 ms | 1420 KiB | 31 Q