3v4l.org

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

Function %00%7Bclosure%7D%2Fin%2FmD2u7%3A9%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mD2u7
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   BIND_STATIC                                              !0
   10     1      > RETURN                                                   !0
   11     2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FmD2u7%3A9%240

Class Foo:
Function getclosure:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mD2u7
function name:  getClosure
number of ops:  7
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV_INIT                                        !0      'foo'
    7     1        ASSIGN_OBJ                                               'bar'
          2        OP_DATA                                                  !0
    9     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FmD2u7%3A9%240'
          4        BIND_LEXICAL                                             ~2, !0
   11     5      > RETURN                                                   ~2
   12     6*     > RETURN                                                   null

End of function getclosure

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.02 ms | 1396 KiB | 15 Q