3v4l.org

run code in 300+ PHP versions simultaneously
<?php header('Content-type: text/plain'); $middleware = ['middle_a', 'middle_b', 'middle_c', 'middle_d', 'middle_e']; function middle_a($output, $next) { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } function middle_b($output, $next) { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } function middle_c($output, $next) { try { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } catch (Exception1 $ex) { echo __FUNCTION__ . ":after\n"; // echo __FUNCTION__ . " caught a `" . get_class($ex) . "` and throws a `Exception2`\n"; // throw new Exception2(-100); return -100; // return $next(-100); } } function middle_d($output, $next) { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } function middle_e($output, $next) { echo __FUNCTION__ . ":before\n"; $output = $next($output+1); echo __FUNCTION__ . ":after\n"; return $output; } class Exception1 extends Exception {} class Exception2 extends Exception {} class Exception3 extends Exception {} function act($input) { echo __FUNCTION__ . ":start\n"; throw new Exception1; return $input; } $pipeline = function($input) { return act($input); }; foreach (array_reverse($middleware) as $cb) { $pipeline = function($input) use ($cb, $pipeline) { return $cb($input, $pipeline); }; } try { var_dump($pipeline(0)); } catch (\Exception $ex) { exit("App caught a `" . get_class($ex) . "`"); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Found catch point at position: 24
Branch analysis from position: 24
2 jumps found. (Code = 107) Position 1 = 25, Position 2 = -2
Branch analysis from position: 25
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/Udr84
function name:  (null)
number of ops:  30
compiled vars:  !0 = $middleware, !1 = $pipeline, !2 = $cb, !3 = $ex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-type%3A+text%2Fplain'
          2        DO_ICALL                                                 
    5     3        ASSIGN                                                   !0, <array>
   61     4        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
          5        ASSIGN                                                   !1, ~6
   64     6        INIT_FCALL                                               'array_reverse'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $8      
          9      > FE_RESET_R                                       $9      $8, ->16
         10    > > FE_FETCH_R                                               $9, !2, ->16
   65    11    >   DECLARE_LAMBDA_FUNCTION                          ~10     [1]
         12        BIND_LEXICAL                                             ~10, !2
         13        BIND_LEXICAL                                             ~10, !1
         14        ASSIGN                                                   !1, ~10
   64    15      > JMP                                                      ->10
         16    >   FE_FREE                                                  $9
   71    17        INIT_FCALL                                               'var_dump'
         18        INIT_DYNAMIC_CALL                                        !1
         19        SEND_VAL_EX                                              0
         20        DO_FCALL                                      0  $12     
         21        SEND_VAR                                                 $12
         22        DO_ICALL                                                 
         23      > JMP                                                      ->29
   73    24  E > > CATCH                                       last         'Exception'
   74    25    >   GET_CLASS                                        ~14     !3
         26        CONCAT                                           ~15     'App+caught+a+%60', ~14
         27        CONCAT                                           ~16     ~15, '%60'
         28      > EXIT                                                     ~16
   75    29    > > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Udr84
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
   62     1        INIT_FCALL                                               'act'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   63     5*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Udr84
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $input, !1 = $cb, !2 = $pipeline
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   66     3        INIT_DYNAMIC_CALL                                        !1
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
   67     8*     > RETURN                                                   null

End of Dynamic Function 1

Function middle_a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Udr84
function name:  middle_a
number of ops:  11
compiled vars:  !0 = $output, !1 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ECHO                                                     'middle_a%3Abefore%0A'
    9     3        INIT_DYNAMIC_CALL                                        !1
          4        ADD                                              ~2      !0, 1
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0  $3      
          7        ASSIGN                                                   !0, $3
   10     8        ECHO                                                     'middle_a%3Aafter%0A'
   11     9      > RETURN                                                   !0
   12    10*     > RETURN                                                   null

End of function middle_a

Function middle_b:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Udr84
function name:  middle_b
number of ops:  11
compiled vars:  !0 = $output, !1 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        ECHO                                                     'middle_b%3Abefore%0A'
   16     3        INIT_DYNAMIC_CALL                                        !1
          4        ADD                                              ~2      !0, 1
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0  $3      
          7        ASSIGN                                                   !0, $3
   17     8        ECHO                                                     'middle_b%3Aafter%0A'
   18     9      > RETURN                                                   !0
   19    10*     > RETURN                                                   null

End of function middle_b

Function middle_c:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 11
Branch analysis from position: 11
2 jumps found. (Code = 107) Position 1 = 12, Position 2 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Udr84
function name:  middle_c
number of ops:  15
compiled vars:  !0 = $output, !1 = $next, !2 = $ex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        ECHO                                                     'middle_c%3Abefore%0A'
   24     3        INIT_DYNAMIC_CALL                                        !1
          4        ADD                                              ~3      !0, 1
          5        SEND_VAL_EX                                              ~3
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !0, $4
   25     8        ECHO                                                     'middle_c%3Aafter%0A'
   26     9      > RETURN                                                   !0
         10*       JMP                                                      ->14
   28    11  E > > CATCH                                       last         'Exception1'
   29    12    >   ECHO                                                     'middle_c%3Aafter%0A'
   32    13      > RETURN                                                   -100
   35    14*     > RETURN                                                   null

End of function middle_c

Function middle_d:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Udr84
function name:  middle_d
number of ops:  11
compiled vars:  !0 = $output, !1 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   38     2        ECHO                                                     'middle_d%3Abefore%0A'
   39     3        INIT_DYNAMIC_CALL                                        !1
          4        ADD                                              ~2      !0, 1
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0  $3      
          7        ASSIGN                                                   !0, $3
   40     8        ECHO                                                     'middle_d%3Aafter%0A'
   41     9      > RETURN                                                   !0
   42    10*     > RETURN                                                   null

End of function middle_d

Function middle_e:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Udr84
function name:  middle_e
number of ops:  11
compiled vars:  !0 = $output, !1 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   45     2        ECHO                                                     'middle_e%3Abefore%0A'
   46     3        INIT_DYNAMIC_CALL                                        !1
          4        ADD                                              ~2      !0, 1
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0  $3      
          7        ASSIGN                                                   !0, $3
   47     8        ECHO                                                     'middle_e%3Aafter%0A'
   48     9      > RETURN                                                   !0
   49    10*     > RETURN                                                   null

End of function middle_e

Function act:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/Udr84
function name:  act
number of ops:  7
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   56     1        ECHO                                                     'act%3Astart%0A'
   57     2        NEW                                              $1      'Exception1'
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   58     5*       RETURN                                                   !0
   59     6*     > RETURN                                                   null

End of function act

Class Exception1: [no user functions]
Class Exception2: [no user functions]
Class Exception3: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.9 ms | 1454 KiB | 17 Q