3v4l.org

run code in 300+ PHP versions simultaneously
<?php $re = new ReflectionClass(A::class); extractMethodBody($re->getMethod('a')); /** * @param \ReflectionMethod $method * @return string */ function extractMethodBody(\ReflectionMethod $method) { $startLine = $method->getStartLine(); $endLine = $method->getEndLine() + 1; $resource = fopen($method->getFileName(), 'r'); $currentLine = 0; while (!feof($resource) && ++$currentLine < $startLine) { fgets($resource, 1024); } $buffer = ''; while (!feof($resource) && ++$currentLine <= $endLine) { $buffer .= fgets($resource, 1024); } preg_match(sprintf('/(?:public|protected|private|final|abstract|static)*?' . '\s+function\s+%s\([^\)]*\)\s*(?:\{(?:[^{}]*|(?R))*\})/sm', preg_quote($method->getName())), $buffer, $matches ); return $matches[0]; } class A { public function test(stdClass $b) { return $b; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bm6ta
function name:  (null)
number of ops:  11
compiled vars:  !0 = $re
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $1      'ReflectionClass'
          1        SEND_VAL_EX                                              'A'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
    5     4        INIT_FCALL_BY_NAME                                       'extractMethodBody'
          5        INIT_METHOD_CALL                                         !0, 'getMethod'
          6        SEND_VAL_EX                                              'a'
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR_NO_REF_EX                                       $4
          9        DO_FCALL                                      0          
   41    10      > RETURN                                                   1

Function extractmethodbody:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 17
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 32
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
Branch analysis from position: 45
Branch analysis from position: 45
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
Branch analysis from position: 29
Branch analysis from position: 29
filename:       /in/bm6ta
function name:  extractMethodBody
number of ops:  63
compiled vars:  !0 = $method, !1 = $startLine, !2 = $endLine, !3 = $resource, !4 = $currentLine, !5 = $buffer, !6 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        INIT_METHOD_CALL                                         !0, 'getStartLine'
          2        DO_FCALL                                      0  $7      
          3        ASSIGN                                                   !1, $7
   14     4        INIT_METHOD_CALL                                         !0, 'getEndLine'
          5        DO_FCALL                                      0  $9      
          6        ADD                                              ~10     $9, 1
          7        ASSIGN                                                   !2, ~10
   16     8        INIT_FCALL                                               'fopen'
          9        INIT_METHOD_CALL                                         !0, 'getFileName'
         10        DO_FCALL                                      0  $12     
         11        SEND_VAR                                                 $12
         12        SEND_VAL                                                 'r'
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !3, $13
   17    15        ASSIGN                                                   !4, 0
   18    16      > JMP                                                      ->21
   19    17    >   INIT_FCALL                                               'fgets'
         18        SEND_VAR                                                 !3
         19        SEND_VAL                                                 1024
         20        DO_ICALL                                                 
   18    21    >   INIT_FCALL                                               'feof'
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                         $17     
         24        BOOL_NOT                                         ~18     $17
         25      > JMPZ_EX                                          ~18     ~18, ->29
         26    >   PRE_INC                                          ~19     !4
         27        IS_SMALLER                                       ~20     ~19, !1
         28        BOOL                                             ~18     ~20
         29    > > JMPNZ                                                    ~18, ->17
   22    30    >   ASSIGN                                                   !5, ''
   23    31      > JMP                                                      ->37
   24    32    >   INIT_FCALL                                               'fgets'
         33        SEND_VAR                                                 !3
         34        SEND_VAL                                                 1024
         35        DO_ICALL                                         $22     
         36        ASSIGN_OP                                     8          !5, $22
   23    37    >   INIT_FCALL                                               'feof'
         38        SEND_VAR                                                 !3
         39        DO_ICALL                                         $24     
         40        BOOL_NOT                                         ~25     $24
         41      > JMPZ_EX                                          ~25     ~25, ->45
         42    >   PRE_INC                                          ~26     !4
         43        IS_SMALLER_OR_EQUAL                              ~27     ~26, !2
         44        BOOL                                             ~25     ~27
         45    > > JMPNZ                                                    ~25, ->32
   27    46    >   INIT_FCALL                                               'preg_match'
         47        INIT_FCALL                                               'sprintf'
   28    48        SEND_VAL                                                 '%2F%28%3F%3Apublic%7Cprotected%7Cprivate%7Cfinal%7Cabstract%7Cstatic%29%2A%3F%5Cs%2Bfunction%5Cs%2B%25s%5C%28%5B%5E%5C%29%5D%2A%5C%29%5Cs%2A%28%3F%3A%5C%7B%28%3F%3A%5B%5E%7B%7D%5D%2A%7C%28%3FR%29%29%2A%5C%7D%29%2Fsm'
         49        INIT_FCALL                                               'preg_quote'
         50        INIT_METHOD_CALL                                         !0, 'getName'
         51        DO_FCALL                                      0  $28     
         52        SEND_VAR                                                 $28
         53        DO_ICALL                                         $29     
         54        SEND_VAR                                                 $29
         55        DO_ICALL                                         $30     
         56        SEND_VAR                                                 $30
   29    57        SEND_VAR                                                 !5
         58        SEND_REF                                                 !6
         59        DO_ICALL                                                 
   32    60        FETCH_DIM_R                                      ~32     !6, 0
         61      > RETURN                                                   ~32
   33    62*     > RETURN                                                   null

End of function extractmethodbody

Class A:
Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bm6ta
function name:  test
number of ops:  3
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   39     1      > RETURN                                                   !0
   40     2*     > RETURN                                                   null

End of function test

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.97 ms | 1404 KiB | 25 Q