3v4l.org

run code in 300+ PHP versions simultaneously
<?php function decorate(callable $fn, array $decorators, array $arguments = array()) { foreach (array_reverse($decorators) as $decorator) { if (is_callable($decorator)) { $fn = $decorator($fn); } } return call_user_func_array($fn, $arguments); } function decorator(callable $decorator) { // This function replaces 'trace' return function($wrapped) use ($decorator) { // This function replaces the function which 'trace' is used on. return function() use ($wrapped, $decorator) { $arguments = func_get_args(); return call_user_func($decorator, $wrapped, $arguments); }; }; } function _trace(callable $fn, array $arguments) { printf("Calling %s with arguments %s\n", print_r($fn, true), print_r($arguments, true)); return call_user_func_array($fn, $arguments); } function trace() { return decorate('_trace', ['decorator'], func_get_args()); } function _foo() { echo "Foo"; } function foo() { return decorate('_foo', ['trace'], func_get_args()); } foo();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lM4H
function name:  (null)
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   INIT_FCALL                                               'foo'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   1

Function decorate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/2lM4H
function name:  decorate
number of ops:  24
compiled vars:  !0 = $fn, !1 = $decorators, !2 = $arguments, !3 = $decorator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <array>
    5     3        INIT_FCALL                                               'array_reverse'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $4      
          6      > FE_RESET_R                                       $5      $4, ->17
          7    > > FE_FETCH_R                                               $5, !3, ->17
    6     8    >   INIT_FCALL                                               'is_callable'
          9        SEND_VAR                                                 !3
         10        DO_ICALL                                         $6      
         11      > JMPZ                                                     $6, ->16
    7    12    >   INIT_DYNAMIC_CALL                                        !3
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0  $7      
         15        ASSIGN                                                   !0, $7
    5    16    > > JMP                                                      ->7
         17    >   FE_FREE                                                  $5
   11    18        INIT_USER_CALL                                0          'call_user_func_array', !0
         19        SEND_ARRAY                                               !2
         20        CHECK_UNDEF_ARGS                                         
         21        DO_FCALL                                      0  $9      
         22      > RETURN                                                   $9
   12    23*     > RETURN                                                   null

End of function decorate

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

End of function decorator

Function %00%7Bclosure%7D%2Fin%2F2lM4H%3A17%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lM4H
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $wrapped, !1 = $decorator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   19     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F2lM4H%3A19%241'
          3        BIND_LEXICAL                                             ~2, !0
          4        BIND_LEXICAL                                             ~2, !1
   22     5      > RETURN                                                   ~2
   23     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F2lM4H%3A17%240

Function %00%7Bclosure%7D%2Fin%2F2lM4H%3A19%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lM4H
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $wrapped, !1 = $decorator, !2 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
   20     2        FUNC_GET_ARGS                                    ~3      
          3        ASSIGN                                                   !2, ~3
   21     4        INIT_USER_CALL                                2          'call_user_func', !1
          5        SEND_USER                                                !0
          6        SEND_USER                                                !2
          7        DO_FCALL                                      0  $5      
          8      > RETURN                                                   $5
   22     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F2lM4H%3A19%241

Function _trace:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lM4H
function name:  _trace
number of ops:  21
compiled vars:  !0 = $fn, !1 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        INIT_FCALL                                               'printf'
          3        SEND_VAL                                                 'Calling+%25s+with+arguments+%25s%0A'
          4        INIT_FCALL                                               'print_r'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $3      
         13        SEND_VAR                                                 $3
         14        DO_ICALL                                                 
   29    15        INIT_USER_CALL                                0          'call_user_func_array', !0
         16        SEND_ARRAY                                               !1
         17        CHECK_UNDEF_ARGS                                         
         18        DO_FCALL                                      0  $5      
         19      > RETURN                                                   $5
   30    20*     > RETURN                                                   null

End of function _trace

Function trace:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lM4H
function name:  trace
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL                                               'decorate'
          1        SEND_VAL                                                 '_trace'
          2        SEND_VAL                                                 <array>
          3        FUNC_GET_ARGS                                    ~0      
          4        SEND_VAL                                                 ~0
          5        DO_FCALL                                      0  $1      
          6      > RETURN                                                   $1
   35     7*     > RETURN                                                   null

End of function trace

Function _foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lM4H
function name:  _foo
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   ECHO                                                     'Foo'
   40     1      > RETURN                                                   null

End of function _foo

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2lM4H
function name:  foo
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   INIT_FCALL                                               'decorate'
          1        SEND_VAL                                                 '_foo'
          2        SEND_VAL                                                 <array>
          3        FUNC_GET_ARGS                                    ~0      
          4        SEND_VAL                                                 ~0
          5        DO_FCALL                                      0  $1      
          6      > RETURN                                                   $1
   45     7*     > RETURN                                                   null

End of function foo

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.3 ms | 1398 KiB | 24 Q