3v4l.org

run code in 300+ PHP versions simultaneously
<?php function decorate(callable $fn) { $decorators = array_slice(func_get_args(), 1); foreach ($decorators as $d) { $wrapper = $d($fn); $fn = $wrapper; } return $wrapper; } function foo($bar) { throw new Exception("Error $bar!"); } function catch_all_exceptions(callable $fn) { return function() use ($fn) { try { return call_user_func_array($fn, func_get_args()); } catch (\Exception $e) { echo "catch_all_exceptions: Caught Exception: $e\n"; } }; } function once(callable $fn) { return function() use ($fn) { static $return; static $called = false; if (!$called) { $return = call_user_func_array($fn, func_get_args()); $called = true; } return $return; }; } function do_something_before(callable $fn) { return function() use ($fn) { echo "Before!\n"; return call_user_func_array($fn, func_get_args()); }; } $bar = decorate(function() { echo "Hello\n"; }, "once"); $bar(); $bar(); $bar(); $foo = decorate("foo", "catch_all_exceptions", "do_something_before"); var_dump($foo("bar"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AuJfV
function name:  (null)
number of ops:  25
compiled vars:  !0 = $bar, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   INIT_FCALL                                               'decorate'
          1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FAuJfV%3A53%243'
          2        SEND_VAL                                                 ~2
          3        SEND_VAL                                                 'once'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !0, $3
   54     6        INIT_DYNAMIC_CALL                                        !0
          7        DO_FCALL                                      0          
   55     8        INIT_DYNAMIC_CALL                                        !0
          9        DO_FCALL                                      0          
   56    10        INIT_DYNAMIC_CALL                                        !0
         11        DO_FCALL                                      0          
   58    12        INIT_FCALL                                               'decorate'
         13        SEND_VAL                                                 'foo'
         14        SEND_VAL                                                 'catch_all_exceptions'
         15        SEND_VAL                                                 'do_something_before'
         16        DO_FCALL                                      0  $8      
         17        ASSIGN                                                   !1, $8
   59    18        INIT_FCALL                                               'var_dump'
         19        INIT_DYNAMIC_CALL                                        !1
         20        SEND_VAL_EX                                              'bar'
         21        DO_FCALL                                      0  $10     
         22        SEND_VAR                                                 $10
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Function decorate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/AuJfV
function name:  decorate
number of ops:  14
compiled vars:  !0 = $fn, !1 = $decorators, !2 = $d, !3 = $wrapper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        FUNC_GET_ARGS                                    ~4      1
          2        ASSIGN                                                   !1, ~4
    7     3      > FE_RESET_R                                       $6      !1, ->11
          4    > > FE_FETCH_R                                               $6, !2, ->11
    8     5    >   INIT_DYNAMIC_CALL                                        !2
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !3, $7
    9     9        ASSIGN                                                   !0, !3
    7    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $6
   12    12      > RETURN                                                   !3
   13    13*     > RETURN                                                   null

End of function decorate

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/AuJfV
function name:  foo
number of ops:  9
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     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
   18     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/AuJfV
function name:  catch_all_exceptions
number of ops:  5
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FAuJfV%3A22%240'
          2        BIND_LEXICAL                                             ~1, !0
   28     3      > RETURN                                                   ~1
   29     4*     > RETURN                                                   null

End of function catch_all_exceptions

Function %00%7Bclosure%7D%2Fin%2FAuJfV%3A22%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 8
Branch analysis from position: 8
2 jumps found. (Code = 107) Position 1 = 9, Position 2 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AuJfV
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $fn, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   BIND_STATIC                                              !0
   24     1        INIT_USER_CALL                                0          'call_user_func_array', !0
          2        FUNC_GET_ARGS                                    ~2      
          3        SEND_ARRAY                                               ~2
          4        CHECK_UNDEF_ARGS                                         
          5        DO_FCALL                                      0  $3      
          6      > RETURN                                                   $3
          7*       JMP                                                      ->13
   25     8  E > > CATCH                                       last         'Exception'
   26     9    >   ROPE_INIT                                     3  ~5      'catch_all_exceptions%3A+Caught+Exception%3A+'
         10        ROPE_ADD                                      1  ~5      ~5, !1
         11        ROPE_END                                      2  ~4      ~5, '%0A'
         12        ECHO                                                     ~4
   28    13      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FAuJfV%3A22%240

Function once:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AuJfV
function name:  once
number of ops:  5
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FAuJfV%3A32%241'
          2        BIND_LEXICAL                                             ~1, !0
   42     3      > RETURN                                                   ~1
   43     4*     > RETURN                                                   null

End of function once

Function %00%7Bclosure%7D%2Fin%2FAuJfV%3A32%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/AuJfV
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $fn, !1 = $return, !2 = $called
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   BIND_STATIC                                              !0
   33     1        BIND_STATIC                                              !1
   34     2        BIND_STATIC                                              !2
   36     3        BOOL_NOT                                         ~3      !2
          4      > JMPZ                                                     ~3, ->12
   37     5    >   INIT_USER_CALL                                0          'call_user_func_array', !0
          6        FUNC_GET_ARGS                                    ~4      
          7        SEND_ARRAY                                               ~4
          8        CHECK_UNDEF_ARGS                                         
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !1, $5
   38    11        ASSIGN                                                   !2, <true>
   41    12    > > RETURN                                                   !1
   42    13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FAuJfV%3A32%241

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

End of function do_something_before

Function %00%7Bclosure%7D%2Fin%2FAuJfV%3A47%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AuJfV
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   BIND_STATIC                                              !0
   48     1        ECHO                                                     'Before%21%0A'
   49     2        INIT_USER_CALL                                0          'call_user_func_array', !0
          3        FUNC_GET_ARGS                                    ~1      
          4        SEND_ARRAY                                               ~1
          5        CHECK_UNDEF_ARGS                                         
          6        DO_FCALL                                      0  $2      
          7      > RETURN                                                   $2
   50     8*     > RETURN                                                   null

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

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

End of function %00%7Bclosure%7D%2Fin%2FAuJfV%3A53%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.64 ms | 1411 KiB | 17 Q