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() { throw new Exception("Error!"); } function catch_all_exceptions() { return function() { try { (yield ["foo" => "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/gj3lo
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/gj3lo
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%2Fgj3lo%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%2Fgj3lo%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 = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gj3lo
function name:  {closure}
number of ops:  26
compiled vars:  !0 = $fn, !1 = $decorator, !2 = $d, !3 = $gen, !4 = $arguments
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  $5      
          4        ASSIGN                                                   !2, $5
    7     5        INIT_DYNAMIC_CALL                                        !2
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !3, $7
    9     8        INIT_METHOD_CALL                                         !3, 'current'
          9        DO_FCALL                                      0  $9      
         10        TYPE_CHECK                                  128          $9
         11      > JMPZ                                                     ~10, ->16
   10    12    >   INIT_METHOD_CALL                                         !3, 'current'
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !4, $11
         15      > JMP                                                      ->18
   12    16    >   FUNC_GET_ARGS                                    ~13     
         17        ASSIGN                                                   !4, ~13
   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  $15     
         23        SEND_VAR_NO_REF_EX                                       $15
         24        DO_FCALL                                      0          
   20    25      > RETURN                                                   null

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

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/gj3lo
function name:  foo
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $0      'Exception'
          1        SEND_VAL_EX                                              'Error%21'
          2        DO_FCALL                                      0          
          3      > THROW                                         0          $0
   26     4*     > 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/gj3lo
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%2Fgj3lo%3A30%241'
   36     1      > RETURN                                                   ~0
   37     2*     > RETURN                                                   null

End of function catch_all_exceptions

Function %00%7Bclosure%7D%2Fin%2Fgj3lo%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/gj3lo
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%2Fgj3lo%3A30%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.76 ms | 1402 KiB | 14 Q