3v4l.org

run code in 500+ PHP versions simultaneously
<?php class TestClass { } $abc = "testABC"; $xyz = new TestClass(); $test = true; $x = function () use ($test, $xyz, $abc) { echo $abc; var_dump($test, $xyz); }; echo packAnonFunction($x, $test, $xyz, $abc); function packAnonFunction($payload, ...$args) { $func = new ReflectionFunction($payload); $filename = $func->getFileName(); $start_line = $func->getStartLine() - 1; $end_line = $func->getEndLine(); $length = $end_line - $start_line; $source = file($filename); $body = implode("", array_slice($source, $start_line, $length)); $body = preg_replace('/(\$[a-z]+)\ \=\ function/', '\\$payload = function', $body); if(preg_match('/use\s\((\$[a-zA-Z0-9]+(?:,\s\$[a-zA-Z0-9]+)*)\)/', $body, $matches)) { $vars = $matches[1]; if(strpos($vars, ', ') !== false) { $parts = explode(', ', $vars); } else { $parts = [$vars]; } $return = []; foreach($parts as $key => $variable) { $return[$variable] = $args[$key]; } $variableString = ""; foreach($return as $var => $value) { $value = serialize($value); $variableString .= "\t{$var} = unserialize('{$value}');\n"; } $body = str_replace(" use (" . $vars . ")", "", $body); $body = str_replace("{\n", "{\n" . $variableString, $body); } return $body; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/89pXm
function name:  (null)
number of ops:  18
compiled vars:  !0 = $abc, !1 = $xyz, !2 = $test, !3 = $x
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                       !0, 'testABC'
    6     1        NEW                                                  $5      'TestClass'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $5
    7     4        ASSIGN                                                       !2, <true>
    8     5        DECLARE_LAMBDA_FUNCTION                              ~9      [0]
          6        BIND_LEXICAL                                                 ~9, !2
          7        BIND_LEXICAL                                                 ~9, !1
          8        BIND_LEXICAL                                                 ~9, !0
          9        ASSIGN                                                       !3, ~9
   13    10        INIT_FCALL_BY_NAME                                           'packAnonFunction'
         11        SEND_VAR_EX                                                  !3
         12        SEND_VAR_EX                                                  !2
         13        SEND_VAR_EX                                                  !1
         14        SEND_VAR_EX                                                  !0
         15        DO_FCALL                                          0  $11     
         16        ECHO                                                         $11
   45    17      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/89pXm
function name:  {closure:/in/89pXm:8}
number of ops:  9
compiled vars:  !0 = $test, !1 = $xyz, !2 = $abc
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   BIND_STATIC                                                  !0
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
    9     3        ECHO                                                         !2
   10     4        INIT_FCALL                                                   'var_dump'
          5        SEND_VAR                                                     !0
          6        SEND_VAR                                                     !1
          7        DO_ICALL                                                     
   11     8      > RETURN                                                       null

End of Dynamic Function 0

Function packanonfunction:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 85
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 49
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 59
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 59
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 59
2 jumps found. (Code = 77) Position 1 = 62, Position 2 = 75
Branch analysis from position: 62
2 jumps found. (Code = 78) Position 1 = 63, Position 2 = 75
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 75
Branch analysis from position: 59
Branch analysis from position: 49
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 59
Branch analysis from position: 53
Branch analysis from position: 59
Branch analysis from position: 85
filename:       /in/89pXm
function name:  packAnonFunction
number of ops:  87
compiled vars:  !0 = $payload, !1 = $args, !2 = $func, !3 = $filename, !4 = $start_line, !5 = $end_line, !6 = $length, !7 = $source, !8 = $body, !9 = $matches, !10 = $vars, !11 = $parts, !12 = $return, !13 = $variable, !14 = $key, !15 = $variableString, !16 = $value, !17 = $var
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        RECV_VARIADIC                                        !1      
   15     2        NEW                                                  $18     'ReflectionFunction'
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !2, $18
   16     6        INIT_METHOD_CALL                                             !2, 'getFileName'
          7        DO_FCALL                                          0  $21     
          8        ASSIGN                                                       !3, $21
   17     9        INIT_METHOD_CALL                                             !2, 'getStartLine'
         10        DO_FCALL                                          0  $23     
         11        SUB                                                  ~24     $23, 1
         12        ASSIGN                                                       !4, ~24
   18    13        INIT_METHOD_CALL                                             !2, 'getEndLine'
         14        DO_FCALL                                          0  $26     
         15        ASSIGN                                                       !5, $26
   19    16        SUB                                                  ~28     !5, !4
         17        ASSIGN                                                       !6, ~28
   21    18        INIT_FCALL                                                   'file'
         19        SEND_VAR                                                     !3
         20        DO_ICALL                                             $30     
         21        ASSIGN                                                       !7, $30
   22    22        INIT_FCALL                                                   'array_slice'
         23        SEND_VAR                                                     !7
         24        SEND_VAR                                                     !4
         25        SEND_VAR                                                     !6
         26        DO_ICALL                                             $32     
         27        FRAMELESS_ICALL_2                implode             ~33     '', $32
         28        ASSIGN                                                       !8, ~33
   23    29        FRAMELESS_ICALL_3                preg_replace        ~35     '%2F%28%5C%24%5Ba-z%5D%2B%29%5C+%5C%3D%5C+function%2F', '%5C%24payload+%3D+function'
         30        OP_DATA                                                      !8
         31        ASSIGN                                                       !8, ~35
   24    32        INIT_FCALL                                                   'preg_match'
         33        SEND_VAL                                                     '%2Fuse%5Cs%5C%28%28%5C%24%5Ba-zA-Z0-9%5D%2B%28%3F%3A%2C%5Cs%5C%24%5Ba-zA-Z0-9%5D%2B%29%2A%29%5C%29%2F'
         34        SEND_VAR                                                     !8
         35        SEND_REF                                                     !9
         36        DO_ICALL                                             $37     
         37      > JMPZ                                                         $37, ->85
   25    38    >   FETCH_DIM_R                                          ~38     !9, 1
         39        ASSIGN                                                       !10, ~38
   26    40        FRAMELESS_ICALL_2                strpos              ~40     !10, '%2C+'
         41        TYPE_CHECK                                      1018          ~40
         42      > JMPZ                                                         ~41, ->49
   27    43    >   INIT_FCALL                                                   'explode'
         44        SEND_VAL                                                     '%2C+'
         45        SEND_VAR                                                     !10
         46        DO_ICALL                                             $42     
         47        ASSIGN                                                       !11, $42
   26    48      > JMP                                                          ->51
   29    49    >   INIT_ARRAY                                           ~44     !10
         50        ASSIGN                                                       !11, ~44
   31    51    >   ASSIGN                                                       !12, <array>
   32    52      > FE_RESET_R                                           $47     !11, ->59
         53    > > FE_FETCH_R                                           ~48     $47, !13, ->59
         54    >   ASSIGN                                                       !14, ~48
   33    55        FETCH_DIM_R                                          ~51     !1, !14
         56        ASSIGN_DIM                                                   !12, !13
         57        OP_DATA                                                      ~51
   32    58      > JMP                                                          ->53
         59    >   FE_FREE                                                      $47
   35    60        ASSIGN                                                       !15, ''
   36    61      > FE_RESET_R                                           $53     !12, ->75
         62    > > FE_FETCH_R                                           ~54     $53, !16, ->75
         63    >   ASSIGN                                                       !17, ~54
   37    64        INIT_FCALL                                                   'serialize'
         65        SEND_VAR                                                     !16
         66        DO_ICALL                                             $56     
         67        ASSIGN                                                       !16, $56
   38    68        ROPE_INIT                                         5  ~59     '%09'
         69        ROPE_ADD                                          1  ~59     ~59, !17
         70        ROPE_ADD                                          2  ~59     ~59, '+%3D+unserialize%28%27'
         71        ROPE_ADD                                          3  ~59     ~59, !16
         72        ROPE_END                                          4  ~58     ~59, '%27%29%3B%0A'
         73        ASSIGN_OP                                         8          !15, ~58
   36    74      > JMP                                                          ->62
         75    >   FE_FREE                                                      $53
   41    76        CONCAT                                               ~63     '+use+%28', !10
         77        CONCAT                                               ~64     ~63, '%29'
         78        FRAMELESS_ICALL_3                str_replace         ~65     ~64, ''
         79        OP_DATA                                                      !8
         80        ASSIGN                                                       !8, ~65
   42    81        CONCAT                                               ~67     '%7B%0A', !15
         82        FRAMELESS_ICALL_3                str_replace         ~68     '%7B%0A', ~67
         83        OP_DATA                                                      !8
         84        ASSIGN                                                       !8, ~68
   44    85    > > RETURN                                                       !8
   45    86*     > RETURN                                                       null

End of function packanonfunction

Class TestClass: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.45 ms | 2157 KiB | 19 Q