3v4l.org

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

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

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

Class Foo: [no user functions]
Class FriendOfFoo:
Function dosomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sku7C
function name:  doSomething
number of ops:  5
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fsku7C%3A9%240'
          2        BIND_LEXICAL                                             ~1, !0
   11     3      > RETURN                                                   ~1
   12     4*     > RETURN                                                   null

End of function dosomething

End of class FriendOfFoo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.09 ms | 1395 KiB | 13 Q