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(); } 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 ["bar"]); } catch (\Exception $e) { echo "Caught Exception: $e\n"; } }; } $foo = decorate("foo", "catch_all_exceptions"); $foo();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MTPo2
function name:  (null)
number of ops:  8
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   INIT_FCALL                                               'decorate'
          1        SEND_VAL                                                 'foo'
          2        SEND_VAL                                                 'catch_all_exceptions'
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   40     5        INIT_DYNAMIC_CALL                                        !0
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Function decorate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MTPo2
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%2FMTPo2%3A5%240'
          3        BIND_LEXICAL                                             ~2, !0
          4        BIND_LEXICAL                                             ~2, !1
   20     5      > RETURN                                                   ~2
   21     6*     > RETURN                                                   null

End of function decorate

Function %00%7Bclosure%7D%2Fin%2FMTPo2%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/MTPo2
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
   16    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
   17    26  E > > CATCH                                       last         'Exception'
   18    27    >   INIT_METHOD_CALL                                         !3, 'throw'
         28        SEND_VAR_EX                                              !5
         29        DO_FCALL                                      0          
   20    30    > > RETURN                                                   null

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

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

End of function catch_all_exceptions

Function %00%7Bclosure%7D%2Fin%2FMTPo2%3A30%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/MTPo2
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   GENERATOR_CREATE                                         
   32     1        YIELD                                                    <array>
          2      > JMP                                                      ->8
   33     3  E > > CATCH                                       last         'Exception'
   34     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
   36     8    > > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FMTPo2%3A30%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.54 ms | 1407 KiB | 14 Q