3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ClosureTester { protected function foo() { return 'bar'; } public function someMethod() { $self = $this; $closure = function() use ($self) { return $self->foo(); }; return $closure(); } } $c = new ClosureTester(); var_dump($c->someMethod());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S2dRu
function name:  (null)
number of ops:  9
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $1      'ClosureTester'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   19     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'someMethod'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FS2dRu%3A11%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S2dRu
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $self
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   BIND_STATIC                                              !0
   12     1        INIT_METHOD_CALL                                         !0, 'foo'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   13     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FS2dRu%3A11%240

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

End of function foo

Function somemethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S2dRu
function name:  someMethod
number of ops:  9
compiled vars:  !0 = $self, !1 = $closure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   FETCH_THIS                                       ~2      
          1        ASSIGN                                                   !0, ~2
   11     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FS2dRu%3A11%240'
          3        BIND_LEXICAL                                             ~4, !0
          4        ASSIGN                                                   !1, ~4
   14     5        INIT_DYNAMIC_CALL                                        !1
          6        DO_FCALL                                      0  $6      
          7      > RETURN                                                   $6
   15     8*     > RETURN                                                   null

End of function somemethod

End of class ClosureTester.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.95 ms | 1396 KiB | 15 Q