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(); // Only call the wrapped function if the decorator made "yield" if (!$gen instanceof \Generator) { return; } 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"; yield; }; } $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/VOchO
function name:  (null)
number of ops:  13
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     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
   54     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/VOchO
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%2FVOchO%3A5%240'
          3        BIND_LEXICAL                                             ~2, !0
          4        BIND_LEXICAL                                             ~2, !1
   26     5      > RETURN                                                   ~2
   27     6*     > RETURN                                                   null

End of function decorate

Function %00%7Bclosure%7D%2Fin%2FVOchO%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Found catch point at position: 30
Branch analysis from position: 30
2 jumps found. (Code = 107) Position 1 = 31, Position 2 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VOchO
function name:  {closure}
number of ops:  35
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
   10     8        INSTANCEOF                                       ~10     !3, 'Generator'
          9        BOOL_NOT                                         ~11     ~10
         10      > JMPZ                                                     ~11, ->12
   11    11    > > RETURN                                                   null
   14    12    >   INIT_METHOD_CALL                                         !3, 'current'
         13        DO_FCALL                                      0  $12     
         14        TYPE_CHECK                                  128          $12
         15      > JMPZ                                                     ~13, ->20
   15    16    >   INIT_METHOD_CALL                                         !3, 'current'
         17        DO_FCALL                                      0  $14     
         18        ASSIGN                                                   !4, $14
         19      > JMP                                                      ->22
   17    20    >   FUNC_GET_ARGS                                    ~16     
         21        ASSIGN                                                   !4, ~16
   22    22    >   INIT_METHOD_CALL                                         !3, 'send'
         23        INIT_USER_CALL                                0          'call_user_func_array', !0
         24        SEND_ARRAY                                               !4
         25        CHECK_UNDEF_ARGS                                         
         26        DO_FCALL                                      0  $18     
         27        SEND_VAR_NO_REF_EX                                       $18
         28        DO_FCALL                                      0          
         29      > JMP                                                      ->34
   23    30  E > > CATCH                                       last         'Exception'
   24    31    >   INIT_METHOD_CALL                                         !3, 'throw'
         32        SEND_VAR_EX                                              !5
         33        DO_FCALL                                      0          
   26    34    > > RETURN                                                   null

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

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/VOchO
function name:  foo
number of ops:  9
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   31     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
   32     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/VOchO
function name:  catch_all_exceptions
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FVOchO%3A36%241'
   42     1      > RETURN                                                   ~0
   43     2*     > RETURN                                                   null

End of function catch_all_exceptions

Function %00%7Bclosure%7D%2Fin%2FVOchO%3A36%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/VOchO
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   GENERATOR_CREATE                                         
   38     1        YIELD                                                    
          2      > JMP                                                      ->8
   39     3  E > > CATCH                                       last         'Exception'
   40     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
   42     8    > > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FVOchO%3A36%241

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

End of function do_something_before

Function %00%7Bclosure%7D%2Fin%2FVOchO%3A47%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/VOchO
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   GENERATOR_CREATE                                         
   48     1        ECHO                                                     'Before%21%0A'
   49     2        YIELD                                                    
   50     3      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FVOchO%3A47%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.79 ms | 1407 KiB | 15 Q