3v4l.org

run code in 300+ PHP versions simultaneously
<?php function decorate(callable $fn, callable $decorator) { return function() use ($fn, $decorator) { $d = $decorator(); $gen = $d(); if (is_array($gen->current())) { $arguments = $gen->current(); } else { $arguments = func_get_args(); } // Forward all throwed Exceptions try { $gen->send(call_user_func_array($fn, $arguments)); } catch (\Exception $e) { $gen->throw($e); } }; } function foo($bar) { throw new Exception("Error $bar!"); } function catch_all_exceptions() { return function() { try { (yield); } catch (\Exception $e) { echo "Caught Exception: $e\n"; } }; } function do_something_before() { return function() { echo "Before!\n"; }; } $foo = decorate(decorate("foo", "catch_all_exceptions"), "do_something_before"); $foo("bar");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2jP1L
function name:  (null)
number of ops:  13
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   INIT_FCALL                                               'decorate'
          1        INIT_FCALL                                               'decorate'
          2        SEND_VAL                                                 'foo'
          3        SEND_VAL                                                 'catch_all_exceptions'
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        SEND_VAL                                                 'do_something_before'
          7        DO_FCALL                                      0  $2      
          8        ASSIGN                                                   !0, $2
   48     9        INIT_DYNAMIC_CALL                                        !0
         10        SEND_VAL_EX                                              'bar'
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Function decorate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2jP1L
function name:  decorate
number of ops:  7
compiled vars:  !0 = $fn, !1 = $decorator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F2jP1L%3A5%240'
          3        BIND_LEXICAL                                             ~2, !0
          4        BIND_LEXICAL                                             ~2, !1
   21     5      > RETURN                                                   ~2
   22     6*     > RETURN                                                   null

End of function decorate

Function %00%7Bclosure%7D%2Fin%2F2jP1L%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Found catch point at position: 26
Branch analysis from position: 26
2 jumps found. (Code = 107) Position 1 = 27, Position 2 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2jP1L
function name:  {closure}
number of ops:  31
compiled vars:  !0 = $fn, !1 = $decorator, !2 = $d, !3 = $gen, !4 = $arguments, !5 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
    6     2        INIT_DYNAMIC_CALL                                        !1
          3        DO_FCALL                                      0  $6      
          4        ASSIGN                                                   !2, $6
    7     5        INIT_DYNAMIC_CALL                                        !2
          6        DO_FCALL                                      0  $8      
          7        ASSIGN                                                   !3, $8
    9     8        INIT_METHOD_CALL                                         !3, 'current'
          9        DO_FCALL                                      0  $10     
         10        TYPE_CHECK                                  128          $10
         11      > JMPZ                                                     ~11, ->16
   10    12    >   INIT_METHOD_CALL                                         !3, 'current'
         13        DO_FCALL                                      0  $12     
         14        ASSIGN                                                   !4, $12
         15      > JMP                                                      ->18
   12    16    >   FUNC_GET_ARGS                                    ~14     
         17        ASSIGN                                                   !4, ~14
   17    18    >   INIT_METHOD_CALL                                         !3, 'send'
         19        INIT_USER_CALL                                0          'call_user_func_array', !0
         20        SEND_ARRAY                                               !4
         21        CHECK_UNDEF_ARGS                                         
         22        DO_FCALL                                      0  $16     
         23        SEND_VAR_NO_REF_EX                                       $16
         24        DO_FCALL                                      0          
         25      > JMP                                                      ->30
   18    26  E > > CATCH                                       last         'Exception'
   19    27    >   INIT_METHOD_CALL                                         !3, 'throw'
         28        SEND_VAR_EX                                              !5
         29        DO_FCALL                                      0          
   21    30    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F2jP1L%3A5%240

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/2jP1L
function name:  foo
number of ops:  9
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        NEW                                              $1      'Exception'
          2        ROPE_INIT                                     3  ~3      'Error+'
          3        ROPE_ADD                                      1  ~3      ~3, !0
          4        ROPE_END                                      2  ~2      ~3, '%21'
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $1
   27     8*     > RETURN                                                   null

End of function foo

Function catch_all_exceptions:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2jP1L
function name:  catch_all_exceptions
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F2jP1L%3A31%241'
   37     1      > RETURN                                                   ~0
   38     2*     > RETURN                                                   null

End of function catch_all_exceptions

Function %00%7Bclosure%7D%2Fin%2F2jP1L%3A31%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 161) Position 1 = -2
Found catch point at position: 3
Branch analysis from position: 3
2 jumps found. (Code = 107) Position 1 = 4, Position 2 = -2
Branch analysis from position: 4
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/2jP1L
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   GENERATOR_CREATE                                         
   33     1        YIELD                                                    
          2      > JMP                                                      ->8
   34     3  E > > CATCH                                       last         'Exception'
   35     4    >   ROPE_INIT                                     3  ~3      'Caught+Exception%3A+'
          5        ROPE_ADD                                      1  ~3      ~3, !0
          6        ROPE_END                                      2  ~2      ~3, '%0A'
          7        ECHO                                                     ~2
   37     8    > > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2F2jP1L%3A31%241

Function do_something_before:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2jP1L
function name:  do_something_before
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F2jP1L%3A42%242'
   44     1      > RETURN                                                   ~0
   45     2*     > RETURN                                                   null

End of function do_something_before

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

End of function %00%7Bclosure%7D%2Fin%2F2jP1L%3A42%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.86 ms | 1407 KiB | 15 Q