3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { protected function ts() { return 3; } public function testclosure() { return function() { return $this->ts(); }; } public function testclosure2() { $this2 = $this; return function() use ($this2) { return $this2->ts(); }; } } $t = new Test; $f1 = $t->testclosure(); echo($f1()."\n"); $f2 = $t->testclosure2(); echo($f1()."\n");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/neHqH
function name:  (null)
number of ops:  18
compiled vars:  !0 = $t, !1 = $f1, !2 = $f2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   NEW                                              $3      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   24     3        INIT_METHOD_CALL                                         !0, 'testclosure'
          4        DO_FCALL                                      0  $6      
          5        ASSIGN                                                   !1, $6
   25     6        INIT_DYNAMIC_CALL                                        !1
          7        DO_FCALL                                      0  $8      
          8        CONCAT                                           ~9      $8, '%0A'
          9        ECHO                                                     ~9
   27    10        INIT_METHOD_CALL                                         !0, 'testclosure2'
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !2, $10
   28    13        INIT_DYNAMIC_CALL                                        !1
         14        DO_FCALL                                      0  $12     
         15        CONCAT                                           ~13     $12, '%0A'
         16        ECHO                                                     ~13
         17      > RETURN                                                   1

Class Test:
Function ts:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/neHqH
function name:  ts
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   3
    6     1*     > RETURN                                                   null

End of function ts

Function testclosure:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/neHqH
function name:  testclosure
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_LAMBDA_FUNCTION                          ~0      [0]
   11     1      > RETURN                                                   ~0
   12     2*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/neHqH
function name:  {closure}
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   FETCH_THIS                                       $0      
          1        INIT_METHOD_CALL                                         $0, 'ts'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   11     4*     > RETURN                                                   null

End of Dynamic Function 0

End of function testclosure

Function testclosure2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/neHqH
function name:  testclosure2
number of ops:  6
compiled vars:  !0 = $this2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_THIS                                       ~1      
          1        ASSIGN                                                   !0, ~1
   16     2        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          3        BIND_LEXICAL                                             ~3, !0
   18     4      > RETURN                                                   ~3
   19     5*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/neHqH
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $this2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   BIND_STATIC                                              !0
   17     1        INIT_METHOD_CALL                                         !0, 'ts'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   18     4*     > RETURN                                                   null

End of Dynamic Function 0

End of function testclosure2

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.51 ms | 1453 KiB | 13 Q